Skip to content
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

Define function as pipe #49074

Closed
dviravr opened this issue Feb 15, 2023 · 3 comments
Closed

Define function as pipe #49074

dviravr opened this issue Feb 15, 2023 · 3 comments

Comments

@dviravr
Copy link

dviravr commented Feb 15, 2023

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

It would be nice to be able to define functions in my component at file as pipe instead of defining class for each pipe.
Sometimes the function is specific to a component and isn’t reusable, but we want it to have a pipe like behavior.

Proposed solution

Add pipe decorator to component’s function

Alternatives considered

Define many specific pipes

@alxhub
Copy link
Member

alxhub commented Feb 15, 2023

Hi @dviravr,

We hear you! I'm going to close this as a duplicate of #46135, but really we see both issues as being special cases of a larger feature request for computed properties (#47553).

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2023
@rosostolato
Copy link

rosostolato commented Mar 2, 2023

@alxhub I believe it could be done something different from what was purposed on those issues you mentioned.

With the new inject function and standalone components, we won't need to create classes for pipes anymore, just a function will be enough. For example:

function namePipe() {
  const myService = inject(MyService);
  return function transform(name: string) {
    return myService.parseName(name);
  }
}

... 

// Then use it on your template
{{ name | name }} 

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants