angular - Ionic 3 ngFor 离子选项值错误
问题描述
i'm building a crud app with ionic 3, the app is working, but i have a problem with the ion-select, it's supposed to load the categories from the database
and it does that, but when select an option throws this error:
这是html代码:
<ion-select [(ngModel)]="categoria" id="categoria" name="categoria"okText="OK" cancelText="Cancelar">
<ion-option *ngFor="let categ of categoria" [value]="categ.id">{{categ.nombre_categoria }}</ion-option>
</ion-select>
这是功能
getCategoria(){
this.NETP.categoria().then(
data=>{
this.categoria = data;
})
}
我不知道怎么了,我是菜鸟,谢谢建议
控制台中的数据看起来像这样
解决方案
在您的代码中,您将选定的选项绑定到您用来迭代的类别。因此,将您的绑定更改为任何其他值 ex : selectedCategoria 并在您的 ts.xml 中声明它。
html: <-- 将类别更改为 selectedCategoria-->
<ion-select [(ngModel)]="selectedCategoria" id="categoria"
name="categoria"okText="OK" cancelText="Cancelar">
<ion-option *ngFor="let categ of categoria" [value]="categ.id">
{{categ.nombre_categoria }}
</ion-option>
</ion-select>
推荐阅读
- javascript - 如何在 React 中像谷歌驱动器这样的响应式卡片网格上进行箭头键导航?
- apache-spark - Power BI 连接到 Cloudera 上的 Hive/Spark
- r - 跳过循环中的迭代
- python - Python安排一个函数每隔几秒运行一次
- python - 在优化之前使用目标函数中的变量值:Python Gurobi
- javascript - HTML,CSS - 滑动时显示两张照片
- php - XAMMP 和 php 中的新功能:安装时出现此错误
- android - jetpack compose 可点击点击效果 类似 iOS
- excel - 需要对 VBA 脚本进行一些解释
- javascript - .Replace 不是替换文本