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 { }
CommonModule
, be sure to import it correctly. – user4676340CommonModule
. – itay odedCommonModule
into the same Module that you declare the component. – 3xGuyViewContainerRef
in the Component, or trying to use it in a Service? – 3xGuy