角度自动分配下拉菜单

问题描述 投票:0回答:1

我在这里有一个下拉角度选择标签。分配值时不会选择下拉菜单。

<select [(ngModel)]="controlType" #ctrl="ngModel" class="form-control" [ngModelOptions]="{standalone: true}">
    <option [value]="undefined" selected>SILA PILIH</option>
    <option *ngFor="let alertControl of alertControlList" [ngValue]="alertControl">{{ alertControl?.desc }}
    </option>
</select>

controlType来自数据库的值

{
    "errorCode": null,
    "errorMessage": null,
    "id": "b9e86e1a-cabc-11e8-9257-31ce15c52e16",
    "createdBy": "a6ef4d81-744e-49e7-9e1d-ab74a14935d6",
    "lastModifiedBy": "a6ef4d81-744e-49e7-9e1d-ab74a14935d6",
    "createdDate": 1538977256000,
    "lastModifiedDate": 1538977256000,
    "deleted": null,
    "active": true,
    "version": 0,
    "code": "1",
    "desc": "why"
}

alertControlList值

[{
    "code": "2",
    "version": "0",
    "desc": "why",
    "id": "b9e8bc3b-cabc-11e8-9257-31ce15c52e16",
    "HEX(id)": "B9E8BC3BCABC11E8925731CE15C52E16"
}, {
    "code": "1",
    "version": "0",
    "desc": "why",
    "id": "b9e86e1a-cabc-11e8-9257-31ce15c52e16",
    "HEX(id)": "B9E86E1ACABC11E8925731CE15C52E16"
}]

仅当我在此处进行对象映射时,它才有效。还有其他更简单的解决方案吗?

for (let int i = 0; i < alertControlList.length; i++) {
    if (alertControlList[i].code === dropdown.code) {
        console.log('do MATCH' + i + ' code' + dropdown.code);
        controlType = alertControlList[i];
    }
}
angular list dropdown
1个回答
0
投票

改为使用[selected]="alertControl.code === dropdown.code"

© www.soinside.com 2019 - 2024. All rights reserved.