GithubHelp home page GithubHelp logo

Comments (17)

swapnil-coditas avatar swapnil-coditas commented on June 11, 2024 19

Same issue with angular 7

from generator-angular2-library.

rtm avatar rtm commented on June 11, 2024 13

The paths option in tsconfig.json worked for me, after futzing around for hours.

"paths": {
  "@angular/*": ["../node_modules/@angular/*"]
}

Adding --preserve-symlinks to the build command, on the other hand, did not work for me.

from generator-angular2-library.

MetaiR avatar MetaiR commented on June 11, 2024 10

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

from generator-angular2-library.

Dmonika04 avatar Dmonika04 commented on June 11, 2024 6

I tired both the above solution, but no success. I am facing following error:
ERROR { Error: StaticInjectorError(AppServerModule)[NgClass -> ElementRef]: StaticInjectorError(Platform: core)[NgClass -> ElementRef]: NullInjectorError: No provider for ElementRef! at NullInjector.module.exports.NullInjector.get ngTempTokenPath: null, ngTokenPath: [ 'NgClass', [Function: ElementRef] ] }
Also, i have upgraded my application from angular5 to angular 6 and trying to implement server-side rendering.
Any solution?

from generator-angular2-library.

AchiraFernando avatar AchiraFernando commented on June 11, 2024 4

Got it working by adding...

    "build": {
      "preserveSymlinks": true
    },

to defaults in .angular-cli.json file

from generator-angular2-library.

guybi avatar guybi commented on June 11, 2024 4

Thanks @AchiraFernando, it's working!

from generator-angular2-library.

callmeaponte avatar callmeaponte commented on June 11, 2024 3

I'm seeing the same issue with Angular 8:

CardComponent.html:13 ERROR NullInjectorError: StaticInjectorError(AppModule)[LinkDirective -> ElementRef]: 
  StaticInjectorError(Platform: core)[LinkDirective -> ElementRef]: 
    NullInjectorError: No provider for ElementRef!

I've tried the following:

  • Deleting node_modules and package-lock.json and running npm install again.
  • Adding "preserveSymlinks": true to build.options in my angular.json file.
  • Updating the paths property in tsconfig.json with "@angular/*": ["../node_modules/@angular/*"].
  • Publishing my changes and loading my library from the npm library, instead of loading it locally.

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

from generator-angular2-library.

AshwaniChoudhary avatar AshwaniChoudhary commented on June 11, 2024 2
"paths": {
    "@angular/*": [
        "./node_modules/@angular/*"
    ]
}

Make the paths mapping in the application's tsconfig (where you are linking to the library) and not the library one.

from generator-angular2-library.

AlanAlbuquerque avatar AlanAlbuquerque commented on June 11, 2024 1

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

from generator-angular2-library.

suneric1 avatar suneric1 commented on June 11, 2024 1

Got it working by adding...

    "build": {
      "preserveSymlinks": true
    },

to defaults in .angular-cli.json file

I think "preserveSymlinks": true should be in build.options

from generator-angular2-library.

alan-albuquerque avatar alan-albuquerque commented on June 11, 2024

same here, any solution?

from generator-angular2-library.

izifortune avatar izifortune commented on June 11, 2024

Can you please post your index.ts or the file containing your @NgModule

from generator-angular2-library.

theunreal avatar theunreal commented on June 11, 2024

@izifortune This is the same file created using the cli, no changes

from generator-angular2-library.

robertbrower-technologies avatar robertbrower-technologies commented on June 11, 2024

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.

from generator-angular2-library.

nathansomething avatar nathansomething commented on June 11, 2024

I tried @AchiraFernando's solution and still getting the same error. I'm using Angular 5.2. Any suggestions?

from generator-angular2-library.

dm-grinko avatar dm-grinko commented on June 11, 2024

Instead of using ElementRef we can use:

import { DOCUMENT } from '@angular/common';
constructor( @Inject(DOCUMENT) private doc ) {}
let [link]: HTMLLinkElement[] = this.doc.querySelectorAll(`[rel="canonical"]`);

from generator-angular2-library.

juanmendes avatar juanmendes commented on June 11, 2024

Instead of using ElementRef we can use:

import { DOCUMENT } from '@angular/common';
constructor( @Inject(DOCUMENT) private doc ) {}
let [link]: HTMLLinkElement[] = this.doc.querySelectorAll(`[rel="canonical"]`);

But that assumes you only have a single instance of your component?

from generator-angular2-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.