tjoskar/ng-lazyload-image

NullInjectorError: No provider for ElementRef!

tjoskar opened this issue · 1 comments

Since version 6, some apps are getting the following error:

ERROR NullInjectorError: "StaticInjectorError(AppModule)[LazyLoadImageDirective -> ElementRef]: 
  StaticInjectorError(Platform: core)[LazyLoadImageDirective -> ElementRef]: 
    NullInjectorError: No provider for ElementRef!
@angular/core@8.0.2
ng-lazyload-image@6.0.0

For some reason (I don't know why) you need to add a path for angular in your tsconfig.json:

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

So it looks something like:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "paths": {
      "@angular/*": ["node_modules/@angular/*"]
    },
    "lib": [
      "es2018",
      "dom"
    ]
  }
}