-
-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
performance question: directive vs pipe #601
Comments
I think that the pipe has better performance advantage, but I don't have any benchmark to support that |
In https://angular-translate.github.io/docs/#/guide/05_using-translate-directive |
This "official" documentation is for "angular-translate", the AngularJS 1.x translate library. |
so, for better performance, what is better to use? pipe or the directive? |
One thing I know, is that
And it really does call it 'all the time'. The comment for that is:
Got it, but seems really inefficient. I'm not sure how is it with directive, will check that. |
Is there any update? |
@bgBond When use pipe transform show first empty string And when use directive, show first path to translate string. But I don't know which performance is better?! I ask this question [here] (https://stackoverflow.com/questions/53156920/which-performance-are-better-ngx-translate-directive-or-pipe) |
Using impure pipes can lead to several performance issues, I tested it and leads to huge number calls in the component, and template rendering, specially if we have a lot of strings or change cycles in your app. I did a similar solution with a pure pipe, with one more input in order to make it change in the language change: where _ is the pipe to call and trans.lang is a public variable of the translate service. In this case the translation will trigger only if the trans.lang changes to another language. |
@albanx can you share the code how did you manage to make the pipe returning the string.
I did something like this but the problem is that call to translate returns Observable. That requires me to chain the |
@piotr-szybicki
The service:
A component usage (that also switch the language):
.html
Hope this helps. The basic idea is that the language get changed/checked only when it changes, not on every change detection cycles. |
I'm submitting a ... (check one with "x")
Is there a performance advantage to using the translate directive vs the (impure) translate pipe?
The text was updated successfully, but these errors were encountered: