为什么在编辑实体角度2时选择未绑定的选项值

时间:2016-09-17 11:18:28

标签: angular

您好我刚刚遇到问题,当我尝试编辑时我有一个下拉列表,并且它没有显示任何值似乎它不想绑定...这是我的代码和结果:

查看:

new_list = []
for item in composite_items:
    element = item.split(":")[1]
    new_list.append(element)
new_set = set(new_list)

这是我的实体:

<select class="form-control" id="selectedCategory" required [(ngModel)]="subCategory.category" name="selectedCategory"> <option *ngFor="let category of categories" [ngValue]="category">{{category.name}}</option> </select>` 上课:

category.ts

import { ICategory } from "../interfaces/icategory"; export class Category implements ICategory { id: number; name: string; image: string; } 上课:

subcagory.ts

这是我通过调试在开发人员控制台中收到的结果:

enter image description here

如果我去表单有空DDL,但我的所有类别都有值...

enter image description here

有谁知道我哪里出错了? :)感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

[(ngModel)]="subCategory.category"引用的值必须是相同的实例,而不是<option *ngFor="let category of categories"中使用的值

如果它只是具有相同内容的对象,则不应该这样做。什么算是对象的身份,而不是内容。

相关问题