【发布时间】:2017-10-03 20:41:23
【问题描述】:
我正在尝试从类别创建单选按钮列表。 类别是一个对象数组,如下所示:
[
{
_id: '58cfb65b2ad6426beec93231'
label: 'Category name',
checked: true
}, {
_id: '58cfb65b2ad6426beec93232'
label: 'Category name 2',
checked: false
}
]
现在我尝试呈现单选按钮列表,并希望通过选中的值设置选中。
<label *ngFor="let cat of categories">
<input
type="radio"
name="category"
[checked]="cat.checked"
[(ngModel)]="selectedCategory"
[value]="cat._id"/>
{{ cat.label[lang.code] }}
</label>
单选按钮都未选中,并且 selectedCategory 未定义。当我提交表单并检查它的值时,它也未定义......有人知道我做错了什么吗?
【问题讨论】: