小编ita*_*ded的帖子

使用ng-packagr组件时“没有ViewContainerRef提供程序”

我使用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)

angular ng-packagr

3
推荐指数
1
解决办法
1754
查看次数

标签 统计

angular ×1

ng-packagr ×1