Add support for component private pipes or pure method calls from templates
See original GitHub issueWhich @angular/* package(s) are relevant/related to the feature request?
core
Description
Currently pipes must be declared at module level. Sometimes a pipe is only used on a single component. The power of pipes being by default pure is that they are only invoked when the input changes. Using a local component function force Angular to always run the function because it has no way to know if the function is pure or not.
Proposed solution
Add a declarations
setting to the Component decorator that allows declaring pipes locally for the component. Another option could be to add a new Pure decorator that can be added to the component method in order to tell Angular that the function invocation from the template gives pure results.
Alternatives considered
Declaring pipes on the module level, this still add too much boilerplate when the pipe is used on a single place.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Impure pipes instead of template function in angular
An impure pipe will be called on every change detection cycle, the same as for a template function. https://angular.io/guide/pipes.
Read more >Transforming Data Using Pipes - Angular
component.ts component binds the pipe's format parameter to the component's format property in the template section, and adds a button for a click...
Read more >The benefits of using pure pipes in Angular templates - Medium
From the article we can learn that Angular optimizes pure pipes by creating just one instance of a pipe regardless of how many...
Read more >Avoid calling expressions in template of Angular - Dev Genius
A pure change is either a change to a primitive input value (String, Number, Boolean, Symbol) or a changed object reference (Date, Array, ......
Read more >Creating A Pipe That Can Consume Component Methods In ...
Ben Nadel demonstrates how to create a generic Pipe in Angular 4.4.0 that allow you to invoke a component method whenever the inputs...
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
Nope, there is no additional overhead for a pipe that’s only used on one component - in fact it will probably be less overhead.
You can achieve this today with standalone components.