Arrays 角离子:尝试区分';值';。只允许使用数组和iterables
我试着显示列表值,当我控制列表的日志值时,它和我想要的完全一样,如下所示Arrays 角离子:尝试区分';值';。只允许使用数组和iterables,arrays,angular,ionic-framework,iterable,Arrays,Angular,Ionic Framework,Iterable,我试着显示列表值,当我控制列表的日志值时,它和我想要的完全一样,如下所示 unit value {id: 81, name: "3 BR Suite"} unit value {id: 82, name: "3 BR Grande"} unit value {id: 83, name: "Pool Villa"} unit value {id: 84, name: "Penthouse"} 但当我尝试用html显示
unit value {id: 81, name: "3 BR Suite"}
unit value {id: 82, name: "3 BR Grande"}
unit value {id: 83, name: "Pool Villa"}
unit value {id: 84, name: "Penthouse"}
但当我尝试用html显示它时,出现了一个错误“尝试区分“Penthouse”时出错。只允许使用数组和iterables”
这是我的.ts代码
private unitList: any = [];
getUnit() {
this.oppCtrl.token_promise.then(() => {
this.oppCtrl.getUnitType(this.productID).subscribe(response => {
response.forEach(data => {
this.unitList = data;
console.log("unit value", this.unitList);
},);
},
(err) => {
let error = err.json();
this.globalService.toastInfo(error.message ? error.message : 'Failed, please check your internet connection...', 3000, 'bottom');
console.log(err);
})
})
}
这是我的html代码
<ion-card *ngFor="let item of unitList" (click)="save(item.id, item.name)">
<ion-list>
<button ion-item style="border-bottom: none !important; padding-bottom: 0px; padding-left: 10px;">
<ion-grid no-padding>
<ion-row>
<ion-col text-left col-12>
<p class="sourceList">{{item.name}}</p>
</ion-col>
</ion-row>
</ion-grid>
</button>
</ion-list>
{{item.name}
你们能帮我解决这个问题吗?非常感谢尝试删除
响应
上的forEach
。实际上,您没有在HTML模板中使用数组
让我们试试这个:
this.oppCtrl.token\u promise.then(()=>{
this.oppCtrl.getUnitType(this.productID).subscribe(response=>{
this.unitList=响应;
console.log(“单位值”,this.unitList);
},
(错误)=>{…})
})
将您的unitList
属性公开:unitList:any=[]代码>
请注意,在开始时,unitList将为空。因此,您的HTML将显示一个空列表。然后,在渲染路由时,您将能够管理数据。
也许你更喜欢使用可观察的