[英]Angular Structural Directives is not working from NPM
sezam-shareds
sezam-shareds
<sezam-overflow [show]="true"></sezam-overflow>
to component in project<sezam-overflow [show]="true"></sezam-overflow>
组件添加到项目中的组件core.js:9847 NG0303: Can't bind to 'ngIf' since it isn't a known property of 'div'
core.js:9847 NG0303: Can't bind to 'ngIf' since it isn't a known property of 'div'
Content of html in package: package中html的内容:
<div *ngIf="show">
...
</div>
Content of html in project:项目中html的内容:
<sezam-overflow [show]="true"></sezam-overflow>
Component in package: package 中的组件:
import { Component, Input, Output, EventEmitter, OnChanges, forwardRef } from '@angular/core';
@Component({
selector: 'sezam-overflow',
templateUrl: `sezam-overflow.component.html`,
})
export class SezamOverflowComponent {
@Input() show = false;
constructor() {}
}
How fix error?如何修复错误?
Can't bind to 'ngIf'
If you would like to install a package, you need to add postintall script to package.json: "postinstall": "ngcc"
如果您想安装 package,您需要将 postintall 脚本添加到 package.json:
"postinstall": "ngcc"
this error is not related to the component.此错误与组件无关。 just add the below code to your module
只需将以下代码添加到您的模块
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
your final code like this你的最终代码是这样的
@NgModule({
imports: [CommonModule,BrowserModule ],
declarations: [SezamOverflowComponent]
})
class AppModule {}
4 things to check:要检查的 4 件事:
SezamOverflowComponent
?SezamOverflowComponent
?exports
contain the SezamOverflowComponent
?exports
是否包含SezamOverflowComponent
? (I'll just assume you called this SezamOverflowModule
...) SezamOverflowModule
...)<sezam-overflow>
on?<sezam-overflow>
? What module declares this component?XxMidule
should import the SezamOverflowModule
XxMidule
应该导入SezamOverflowModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.