Angular &引用;ViewContainerRef没有提供程序;使用ng Packager组件时
我已经使用angular cli创建了一个组件库, 在模块内部使用Angular &引用;ViewContainerRef没有提供程序;使用ng Packager组件时,angular,ng-packagr,Angular,Ng Packagr,我已经使用angular cli创建了一个组件库, 在模块内部使用*ngIf的组件 在我的主项目中成功构建并安装库之后, 当我尝试使用该组件时,我发现ViewContainerRef没有提供程序 版本: @angular/cli版本:“~7.0.6” @角度/*版本:“~7.0.0” 错误: 错误:StaticInjectorError(AppModule)[NgIf->ViewContainerRef]: StaticInjectorError(平台:核心)[NgIf->ViewContain
*ngIf
的组件
在我的主项目中成功构建并安装库之后,
当我尝试使用该组件时,我发现ViewContainerRef没有提供程序
版本:
@angular/cli版本:“~7.0.6”
@角度/*版本:“~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() {
}
}
模板:
<div *ngIf="header">
</div>
我发现了问题所在, 通过向我的主项目的angular.json文件中添加
“preserveSymlinks”:true
解决了这个问题
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"preserveSymlinks": true,
...
这就是我找到解决方案的地方:
它来自
CommonModule
,请确保正确导入。感谢快速响应,我正在导入CommonModule
。请确保将CommonModule
导入到声明组件的同一个模块中。这是我的模块:@NgModule({声明:[CardComponent],导入:[CommonModule],导出:[CardComponent],})导出类CardModule{}您是在组件中使用ViewContainerRef
,还是试图在服务中使用它?Angluar 8不存在,怎么会这样?@itay oded它在ng serve上不起作用,有什么想法吗?我想这是--prod profile适用于我的Angular 8和ng serve。这解决了我在尝试将bti用于Angular时遇到的问题!谢谢
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"preserveSymlinks": true,
...