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.

Unable to inject standalone pipe into a service

See original GitHub issue

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

github_iconTop GitHub Comments

2reactions
jnizetcommented, Sep 5, 2022

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).

0reactions
angular-automatic-lock-bot[bot]commented, Oct 6, 2022

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.

Read more comments on GitHub >

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

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