How to declare pipe at component level?
See original GitHub issueI got a pipe that is used only in one component. So I wanted to declare pipe at this component level. Something like this:
@Component({
selector: 'app-my-comp',
templateUrl: './my-comp.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
declarations: [MyCustomPipe]
})
export class MyComponent {
}
However the Component
annotation doesn’t support declarations
.
Is there anyway to achieve this? I know I can declare pipe in the module but then other components will be “notified” about it and it will break encapsulation.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Using Custom Pipes in a Component Class in Angular
It's easy to create custom pipes to use in your templates to modify interpolated values. You don't have to duplicate your code if...
Read more >How to Use an Angular Pipe in a Component File - Medium
Create a simple Angular application via the Angular CLI by running the following command. ng new pipe-in-component --defaults. Using the pipe in ...
Read more >How to create and call a pipe from the component in Angular 2?
If you want to call the pipe directly within the component class, you need to instantiate it and call its tranform method: @Component({...
Read more >Adding Components, Pipes and Services to a Module
Our modules are usually made up of multiple components, services, directives and pipes. In this chapter we are going to extend the example...
Read more >Custom Pipes in Angular With Examples
Create a file named custom.pipe.ts ; Use The Pipe decorator (@Pipe) to define the pipe name that will be used within the components....
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 Free
Top 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
Declaring and providing something are different concepts, so I’m not sure why this would be “inconsistent”. You can, in fact, provide a pipe on a component much like you can provide a service.
Is there any reason why you absolutely need to scope the pipe’s declaration to this component? Just don’t use it elsewhere. If you really want to bundle it closely together, wrap them both into a separate module and don’t export the pipe.
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.