【发布时间】:2021-01-06 13:46:49
【问题描述】:
我正在尝试使用 ngFor 来遍历列表中的项目。但是,我在浏览器上收到此警告,并且列表未显示。我该如何解决?我已经在app.module.ts 中的@NgModule 导入中添加了BrowserModule 和CommonModule。这并没有解决问题。
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { CommonModule } from "@angular/common"; //if we want to use ngFor and other types //then we need to include common module to be able to use it
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
CommonModule,
IonicModule.forRoot(),
AppRoutingModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
锻炼计划.page.html
<ion-header>
<ion-toolbar>
<ion-title>workoutplan !!</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor ="let workoutplan of workoutPlans">
{{workoutplan.title}}
</ion-item>
</ion-list>
</ion-content>
【问题讨论】:
标签: angular ionic-framework ionic4 ngfor