angular - Ionic 中的 nfFor 命令在组件内不起作用
问题描述
我正在 Ionic / Angular 中创建一个 Ionic 应用程序。我创建了一些页面并且工作正常。但是现在我正在尝试创建一个组件,但我不能使用 *ngFor 命令。
我使用 Ionic cli 创建了组件。这是我的 HTML:
<ion-item button *ngFor="let myItem of myCollection">
(...)
</ion-item>
我已经在页面中使用了 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:\Users\User\AppData\Roaming\npm\node_modules\@ionic\cli)
Ionic Framework : @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
解决方案
由于您的组件没有模块,因此您需要在要添加组件的页面模块内的声明中添加组件。请参阅下面的示例代码:
@NgModule({
imports: [
BrowserModule,
CommonModule,
....
],
declarations: [
UserComponent // Add the components name to the module declarations
]
})
export class SamplePageModule {}
推荐阅读
- excel - 如何多次复制两个特定的行和列?
- ionic3 - 使用 Android 权限插件 Ionic 3 Angular 5 时,Object(...) 不是函数
- c# - 如何避免匹配以#开头的数字字符串?
- bash - Bash printf: how to understand zero dot s ("%0.s") syntax
- javascript - 如何在 Jquery 中的两个事件函数之间传递变量?
- postgresql - 如何让我办公室的其他人访问我的数据库?
- python - Python 请求 API 在解码 json 时显示错误
- python - 使用 for 循环遍历 sqlalchemy 数据库进入无限循环
- git - GitHub 向新分支创建拉取请求?
- c# - 无法将“System.Object []”类型的对象转换为我的类 C#