Unable to inject standalone pipe into a service
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
compiler
Is this a regression?
No
Description
I have a standalone Pipe that I want to inject into a service with @Injectable({ providedIn: ‘root’ }).
The @Injectable decorator is missing the imports field.
Or am I missing something?
Thanks, Paul
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
At runtime I get the following error:
R3InjectorError(AppModule)[MyService -> MyStandaloneService]: NullInjectorError: No provider for CurrencySterlingPipe!.
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 14.2.0
Node: 16.15.0
Package Manager: npm 8.5.5
OS: win32 x64
Angular: 14.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
... youtube-player
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1402.0
@angular-devkit/build-angular 14.2.0
@angular-devkit/core 14.2.0
@angular-devkit/schematics 14.2.0
@nguniversal/common 14.1.0
@schematics/angular 14.2.0
rxjs 7.5.6
typescript 4.8.2
Anything else?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Angular - Use pipes in services and components
I got an error because DatePipe is not a provider, so it cannot be injected. One solution is to put it as a...
Read more >[Complete] RFC: Standalone components, directives and ...
This means that the single exported standalone component, directive or pipe is added to the compilation scope of the importing NgModule .
Read more >NG0302: Pipe not found! - Angular
Angular can't find a pipe with this name. The pipe referenced in the template has not been named or declared properly. In order...
Read more >Angular Inject & Injection Functions - Patterns & Anti-Patterns
Angular Injection Functions can only be used in the construction context of a declarable (e.g. component, directive, pipe) or a service.
Read more >A guide to Standalone Components in Angular - Ninja Squad
This is true for every component/directive/pipe you use in a standalone component. So if the template of UserComponent also uses a ...
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
IMHO, a pipe should never be injected anywhere. If you need the funtionality of the pipe outside of a template, then extract the logic of the pipe in a function and use that function everywhere you need it (including the pipe), or extract the logic of the pipe into a service, and inject that service anywhere you need it (including 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.