-
Notifications
You must be signed in to change notification settings - Fork 122
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
NullInjectorError: No provider for ElementRef! #281
Comments
same here, any solution? |
Can you please post your index.ts or the file containing your |
@izifortune This is the same file created using the cli, no changes |
As a quick test I simply renamed my directive selector to bsRotate and added it to the component markup. I did not get the error. I got other errors though. I had to restart the playground a few times. I verified the directive was applied. |
It's relationed to install the library from local dir directly, when I publish the library to NPM and install from npm servers, works perfect |
Got it working by adding...
to defaults in .angular-cli.json file |
Thanks @AchiraFernando, it's working! |
I tried @AchiraFernando's solution and still getting the same error. I'm using Angular 5.2. Any suggestions? |
The
Adding |
I tired both the above solution, but no success. I am facing following error: |
Same issue with angular 7 |
I had the same problem and I removed node_module folder and yarn.lock (or package-lock.json in case u are using npm) and installed dependencies again, now my problem is solved, hope it's helpful installing dependencies by: yarn install # or npm install |
I think |
Make the |
Instead of using ElementRef we can use:
|
But that assumes you only have a single instance of your component? |
I'm seeing the same issue with Angular 8:
I've tried the following:
... None of this worked. I can only get my attribute directive to work if I host it inside my project instead of attempting to load it as a third-party library. I've even tried copying and pasting the attribute directive from the Angular docs as-is, without modifications, and the error still occurs. I suspect this might be an issue with Angular itself, where attempting to load and use attribute directives from libraries simply doesn't work. |
When I'm simply trying to put el: ElementRef in my directive constructor and use it in my component, I get the following error:
component:
template: `<div><h1 class="rotateBox" bsRotate>Test</h1></div>`,
directive:
Why i'm unable to use the element reference in my directive when generating a library?
The text was updated successfully, but these errors were encountered: