我有一个动态列表,其中包含一些输入和选择字段,并且我想使用这些字段来绑定动态数据。我尝试使用ngModel进行绑定,但是它仅显示最后一个对象的条目。这是我要绑定的数据
properties=[
{
"Id": "01",
"PropertyType": null,
"PropertyTypeId": 1,
"PropertyName": "Name",
"AdditionalList": []
},
{
"Id": "02",
"PropertyType": null,
"PropertyTypeId": 1,
"PropertyName": "Phone",
"AdditionalList": []
},
{
"Id": "03",
"PropertyType": null,
"PropertyTypeId": 1,
"PropertyName": "Work Phone",
"AdditionalList": []
}]
预先感谢...
答案 0 :(得分:0)
propertyTypes= [
{ id: 1, name: "List" },
{ id: 2, name: "Text" },
];
selectedValue = null;
这就是绑定所选值的方式
<select [(ngModel)]="selectedValue" (click)="showSelected()">
<option *ngFor="let c of propertyTypes" [ngValue]="c.type">
{{ c.type }}
</option>
</select>
这是一个提示,说明如何使用showselected方法处理的选定对象
showSelected(item) {
console.log(this.selectedValue);
}