0

I was wondering about this issue about the "t" function transloco uses in its directive.

When we use functions in our template in angular for, lets say, showing users email. So we write something like:

<div>
  {{getUserEmail()}}
</div>

From my knowledge of angular, unless you put OnPush detection strategy, this function will get called on every change detection. This is why it's recommended to use pipes when possible because they are not subject to this problem.

So my question is, does the 't' function of transloco somehow avoid this call every time or not? Or am I missunderstanding transloco/angular?

P.S. I know the function is memoized but it would still be better if it's not called every change detection.

I'm considering using transloco pipe mostly because it seems to me like it's better to have more subscriptions in the app then having "t" function called a bunch of times. Maybe my perception is wrong?

zvocs
  • 1
  • 2
  • `This is why it's recommended to use pipes when possible because they are not subject to this problem.` Not totally true. Only `pure` pipes are not affected by that. Since every possible pipe that do a translation change its input - hence the output is different - it will trigger a change detection. – Jacopo Sciampi Mar 16 '23 at 15:42
  • So if I understand you correctly even the transloco pipe will trigger on every change detection? So it's basically the same for me? – zvocs Mar 17 '23 at 09:40
  • Yep. Rather than using `OnPush` there's nothing much you can do. Besides, these changes have little impact on the overall performances so I'd even not worry that much – Jacopo Sciampi Mar 17 '23 at 16:01

0 Answers0