performance question: directive vs pipe
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Is there a performance advantage to using the translate directive vs the (impure) translate pipe?
Issue Analytics
- State:
- Created 6 years ago
- Comments:11
Top Results From Across the Web
Angular 2 impure pipe vs directive performance - Stack Overflow
The pipe is an Impure pipe that can handle the translation and any async loading of text. The downside to this approach that...
Read more >Angular Performance: Optimizing Expression Re-evaluation ...
A pure pipe is only re-evaluated when either the inputs or any of the arguments change. So how does this matter in our...
Read more >Difference between Angular directives vs components - eduCBA
Guide to Angular directives vs components. Here we discuss the Angular directives vs components key differences with comparison table.
Read more >Built-in directives - Angular
Use Angular's built-in directives to manage forms, lists, styles, and what users ... Attribute directives, Change the appearance or behavior of an element, ......
Read more >Pipe vs Directive in Angular - Geekboots
Pipe vs Directive · A user creates/uses a directive that parses the input into a formatted currency string. · Pipes are for formatting...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@piotr-szybicki The pipe
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.
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: {{‘Hello’ | _:trans.lang}}
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.