我正在Ionic/Angular中創建一個Ionic App。我創建了一些頁面,它的作業很好。但現在我試圖創建一個組件,但我不能使用*ngFor命令。
我使用Ionic cli創建了組件。這是我的HTML:
<ion-item button *ngFor="let myItem of myCollection" >
(...)
</ion-item>
我已經在一個頁面中使用了ngFor,并且成功了,但已知在組件中我得到了以下錯誤:
core.jewelry.com
我已經在一個頁面中使用了ngFor,并且成功了。
core.js:10140 NG0303: Can't bind to 'ngForOf' since it isn't a known property of 'ion-item'.
我搜索過這個問題,有人建議我把BrowserModule放在App中,把CommonModule放在我的頁面模塊中。我的應用程式已經有了,每個頁面也有,但我的組件沒有模塊檔案,我應該把它放在哪里?或者我怎樣才能解決這個問題?
這些是我使用的版本 :
Ionic CLI : 6.16.1 (C:UsersUserAppDataRoaming)
pm
ode_modules@ioniccli)
Ionic框架。@ionic/angular 5.6.9
@angular-devkit/build-angular : 0.1102.14
@angular-devkit/schematics : 11.2.14
@angular/cli : 11.2.14
@ionic/angular-toolkit : 3.1.1
uj5u.com熱心網友回復:
由于你的組件沒有模塊,你需要在你想添加組件的頁面模塊里面的declarations中添加你的組件。請看下面的示例代碼:
@NgModule({
進口。[
BrowserModule,
CommonModule,
....
],
宣告。[
UserComponent // 在模塊宣告中加入組件的名字
]
})
export class SamplePageModule {}.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/333026.html
標籤:
