NullInjectorError: No provider for ElementRef!
See original GitHub issueWhen I’m simply trying to put el: ElementRef in my directive constructor and use it in my component, I get the following error:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[SampleDirective -> ElementRef]:
StaticInjectorError(Platform: core)[SampleDirective -> ElementRef]:
NullInjectorError: No provider for ElementRef!
Error: StaticInjectorError(AppModule)[SampleDirective -> ElementRef]:
StaticInjectorError(Platform: core)[SampleDirective -> ElementRef]:
NullInjectorError: No provider for ElementRef!
component:
template: `<div><h1 class="rotateBox" bsRotate>Test</h1></div>`,
directive:
@Directive({
selector: '[bsRotate]'
})
export class SampleDirective {
constructor(el: ElementRef) {
console.log(el);
}
}
Why i’m unable to use the element reference in my directive when generating a library?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:17
Top Results From Across the Web
NullInjectorError: No provider for ElementRef - Stack Overflow
I got this NullInjector error when trying to use a UI control from a shared library module, adding the @angular path to my...
Read more >NullInjectorError: No provider for ElementRef - EJ 2 Forums
to upload a document. But when I run the application with ng serve, I'm getting this error in the localhost. ERROR Error: StaticInjectorError( ......
Read more >Angular – NullInjectorError: No provider for ElementRef
I created an internal directive in a module in my project (Angular 8 + Material Design). Following tuto and official doc. Ok, it's...
Read more >Unhandled Promise rejection: No provider for ElementRef
There is something else wrong in your application. Some other hints: `bindings` is deprecated in favor of `providers`.
Read more >Dependency injection in action - Angular
The first injector configured with a provider supplies the dependency (a service instance or value) to the constructor; If no provider is found...
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
Same issue with angular 7
The
paths
option intsconfig.json
worked for me, after futzing around for hours.Adding
--preserve-symlinks
to the build command, on the other hand, did not work for me.