5

I'm using ngx-translate 11.x with angular 7 in a huge project.

When use pipe transform show first empty string And when use directive, show first path to translate string.

Directive way: <span [translate]="HELLO'"></span>

Pipe way: <span >{{'HELLO'| translate}}</span>

Now, Which performance are better?

Morteza QorbanAlizade
  • 1,520
  • 2
  • 19
  • 35
  • Well if you're looking for performance, the built-in i18n tool is the best one, since you compile every project into a different language. Otherwise, I would say the pipe, because directives are heavier since they manipulate the HTML while the pipe only transforms the data that is provided to them, but I'm not sure. –  Nov 05 '18 at 15:19
  • AFAIK the `translate` pipe implementation is impure so there might be some performance hits (multiple instances for each component, pipe called on each change detection cycle, etc.). – Andrei Tătar Nov 05 '18 at 15:38

1 Answers1

0

There is the official i18n module for performances.
Also with ngx-translate you can write something like this: <span [innerHtml]="'HELLO'" translate></span>

Marc
  • 234
  • 1
  • 2