- 我已經創建了 npm 包
sezam-shareds - 將包安裝到新專案
- 從此包中添加了組件:
<sezam-overflow [show]="true"></sezam-overflow>到專案中的組件 - 瀏覽器控制臺出現錯誤:
core.js:9847 NG0303: Can't bind to 'ngIf' since it isn't a known property of 'div'
包中的html內容:
<div *ngIf="show">
...
</div>
專案中的html內容:
<sezam-overflow [show]="true"></sezam-overflow>
封裝組件:
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() {}
}
如何修復錯誤? Can't bind to 'ngIf'
如果你想安裝一個包,你需要在 package.json 中添加 postintall 腳本:
"postinstall": "ngcc"
uj5u.com熱心網友回復:
此錯誤與組件無關。只需將以下代碼添加到您的模塊
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
你的最終代碼是這樣的
@NgModule({
imports: [CommonModule,BrowserModule ],
declarations: [SezamOverflowComponent]
})
class AppModule {}
uj5u.com熱心網友回復:
要檢查的 4 件事:
- 什么模塊宣告了
SezamOverflowComponent? - 這個模塊是否
exports包含SezamOverflowComponent?(我只是假設你稱之為SezamOverflowModule......) - 你在使用什么組件
<sezam-overflow>?什么模塊宣告了這個組件?(假設 XxMidule ...) - 這
XxMidule應該匯入SezamOverflowModule
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/407334.html
標籤:
上一篇:驗證NPM包是否是官方的
