x)- [x] bug report -> please search issues before submitting
- [ ] feature request
- [x] devkit
- [ ] schematics
Angular CLI: 6.0.8
Node: 8.11.1
OS: win32 x64
Angular: 6.0.7
NPM: 6.0.0
import { Component } from '@angular/core';
@Component({
selector: 'common-components-test',
template: '<div>{{test}}</div>'
})
export class SideMenuComponent {
public test: string = 'test 1';
constructor() { }
}
Expected & actual: 'test 1' is visible on the screen
import { Component } from '@angular/core';
@Component({
selector: 'common-components-test',
template: '<div *ngFor="let item of items">{{item}}</div>'
})
export class SideMenuComponent {
public items: string[] = ['1', '2'];
constructor() { }
}
import { CommonModule } from '@angular/common';
imports: [ CommonModule ]
Expected: '1 2' is visible on the screen
Actual: nothing is visible on the screen. Opening the console reveals the following error:
ERROR Error: StaticInjectorError(AppModule)[NgForOf -> ViewContainerRef]:
StaticInjectorError(Platform: core)[NgForOf -> ViewContainerRef]:
NullInjectorError: No provider for ViewContainerRef!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1034)
at resolveToken (core.js:1273)
at tryResolveToken (core.js:1218)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveToken (core.js:1273)
at tryResolveToken (core.js:1218)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveNgModuleDep (core.js:8168)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:8856)
at resolveDep (core.js:9221)
I would like to use angular directives inside of an angular library
An example of this is on: https://github.com/rpasechnikov/angularSharedLibraryExample
Since you are using file property in package.json to resolve your library instead of tsconfig paths. You need to enable preserveSymlinks inside your build configuration in angular.json
In your angular.json locate build property under the architect, and in options add "preserveSymlinks": true
That did it! Thanks Alan!
Do you mind elaborating a bit on the option? "Do not use the real path when resolving modules" - what is a real path and what exactly happens under the hood?
This is the documentation that I was able to find: https://github.com/angular/angular-cli/wiki/angular-cli
This is a TypeScript flag.
Here are some useful links that explains this in more detail:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-5.html
https://nodejs.org/api/cli.html#cli_preserve_symlinks
Thanks so much! 馃憤
I've updated the sample solution with a few shared components, etc. Hopefully this may serve as a basic example for someone else struggling with these basic concepts:
im just developing a pure angular library, and i can not add "preserveSymlinks": true in build options, when i npm link my library, i got the same error like
Error: StaticInjectorError(AppModule)[HttpHandler -> Injector]:
StaticInjectorError(Platform: core)[HttpHandler -> Injector]:
NullInjectorError: No provider for Injector!
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._
Most helpful comment
Since you are using
fileproperty in package.json to resolve your library instead of tsconfig paths. You need to enablepreserveSymlinksinside your build configuration inangular.jsonIn your
angular.jsonlocatebuildproperty under thearchitect, and inoptionsadd"preserveSymlinks": true