Reputation: 1040
I have created a components library using angular cli ng generate library
,
with a component that uses *ngIf
inside a module.
After successfully build and install the library in my main project,
when I try to use the component I am getting No provider for ViewContainerRef
error.
Versions:
@angular/cli version: "~7.0.6",
@angular/* version : "~7.0.0"
Error:
ERROR Error: StaticInjectorError(AppModule)[NgIf -> ViewContainerRef]: StaticInjectorError(Platform: core)[NgIf -> ViewContainerRef]: NullInjectorError: No provider for ViewContainerRef!
component:
import {Component, OnInit, Input} from '@angular/core';
@Component({
selector: 'al-card',
templateUrl: './card.component.html',
styleUrls: ['./card.component.scss']
})
export class CardComponent implements OnInit {
@Input() header: string;
@Input() text: string;
constructor() { }
ngOnInit() {
}
}
template:
<div *ngIf="header">
</div>
module:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CardComponent } from './card.component';
@NgModule({
declarations: [CardComponent],
imports: [
CommonModule
],
exports: [CardComponent],
})
export class CardModule { }
Upvotes: 3
Views: 6388
Reputation: 1040
I have found out the problem,
it solved by adding "preserveSymlinks": true
to my main project's angular.json file.
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"preserveSymlinks": true,
...
this is where I have found the solution: https://github.com/angular/angular-cli/issues/10896
Upvotes: 9