我使用angular cli 创建了一个组件库ng generate library
,并*ngIf
在模块内部使用了一个组件。
在我的主项目中成功构建并安装了库之后,尝试使用该组件时No provider for ViewContainerRef
出现错误。
版本:
@ angular / cli版本:“〜7.0.6”,
@ angular / *版本:“〜7.0.0”
错误:
错误错误:StaticInjectorError(AppModule)[NgIf-> ViewContainerRef]:StaticInjectorError(平台:核心)[NgIf-> ViewContainerRef]:NullInjectorError:ViewContainerRef没有提供者!
零件:
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() {
}
}
Run Code Online (Sandbox Code Playgroud)
模板:
<div *ngIf="header">
</div>
Run Code Online (Sandbox Code Playgroud)
模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; …
Run Code Online (Sandbox Code Playgroud)