question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for component private pipes or pure method calls from templates

See original GitHub issue

Which @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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alxhubcommented, Sep 26, 2022

Nope, there is no additional overhead for a pipe that’s only used on one component - in fact it will probably be less overhead.

1reaction
pkozlowski-opensourcecommented, Sep 23, 2022

Add a declarations setting to the Component decorator that allows declaring pipes locally for the component

You can achieve this today with standalone components.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found