【发布时间】:2019-08-14 10:10:15
【问题描述】:
我正在创建一个 Ionic/Angular 应用程序,我想在使用 *ngFor 的语句中显示列表中的值。但由于某种原因,*ngFor 什么也没做。
*ngFor 在我说*ngFor="let i of eventList" 时不会运行,但是当我将变量的值放在里面时会运行
*ngFor="let i of {'id': 1, 'name':'Superman'},{'id' :2,'name':'Batman'},
{'id' : 5, 'name':'BatGirl'},
{'id' : 3, 'name':'Robin'},
{'id' : 4, 'name':'Flash'}
];"
然后它运行。
这是我的 tab1.module.ts 和 html
import { RouterModule } from '@angular/router';
import { NgModule, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Tab1Page } from './tab1.page';
import { AuthService} from '../auth.service';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
IonicModule,
CommonModule,
FormsModule,
HttpClientModule,
RouterModule.forChild([{ path: '', component: Tab1Page }])
],
declarations: [Tab1Page]
})
export class Tab1PageModule
{
public eventList: {'id': number, 'name': string}[] =[{'id': 1, 'name':'Superman'},
{'id' : 2, 'name':'Batman'},
{'id' : 5, 'name':'BatGirl'},
{'id' : 3, 'name':'Robin'},
{'id' : 4, 'name':'Flash'}
];
public message: any = '';
constructor(public auth: AuthService)
{
}
}
html
<ion-item >
<ion-input type="number" clearInput></ion-input>
<ion-select placeholder="Select One" >
<ion-select-option *ngFor="let i of eventList" value="{{i.id}}">
{{i.name}}
</ion-select-option>
</ion-select>
</ion-item>
当我运行它时,选择框保持为空。我也尝试了许多不同的方法和变量的格式,但它什么也没做。
【问题讨论】: