问题:我的ngfor在运行Web时运行完美,但是当ı在真实设备上模拟我的应用程序时,它只是无法工作。我到处看 互联网寻求解决方案,但找不到,就像一个封闭的(那 我怎么想),有人说这是ngZone问题,我没有任何 知道是什么。
我的服务
getMenuObject(): Observable<any> {
return this.http
.post("xxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxxxx",{ HotelId:25, GroupId:9 });
}
我的.ts
data: Array<any>=[]
ngOnInit(){
this.httpService.getMenuObject().toPromise().then(x=>{
this.data = x;
console.log(this.data)
if(x.IsGroup==true){
this.splashScreen.hide();
} else{
this.router.navigate(['folder/Inbox']);
}
});
}
我的html:
<ion-card *ngFor="let otel of data.MobileHotelDefinitions" style="margin: 40px 0;border-radius: 0;">
<ion-card-header style="padding: 0;">
<ion-img (click)="goToHotel()" [src]="otel.MobileApplicationDefinition.GroupImageUrl"></ion-img>
<div class="otelName">
<div style="flex: 1;">{{otel.Name}}</div>
<div style="color: goldenrod;">★★★★★</div>
</div>
</ion-card-header>
<ion-card-content>
Keep close to Nature's heart... and break clear away, once in awhile,
and climb a mountain or spend a week in the woods. Wash your spirit clean.
</ion-card-content>
</ion-card>
我在网络浏览器上的应用(离子服务--o):
*ngIf
检查。data
变量不是数组。其中的MobileHotelDefinitions
属性是数组。因此,最好将其类型定义为any
而不是Array
。?.
。它会在尝试访问父属性之前检查其父属性是否已定义。控制器
?.
模板
data: any; // <-- `any` here
ngOnInit() {
this.httpService.getMenuObject().subscribe(
response => {
this.data = response;
console.log(this.data);
if (response.IsGroup == true) {
this.splashScreen.hide();
} else {
this.router.navigate(['folder/Inbox']);
}
},
error => {
// always good practice to handle HTTP errors
}
);
}