[英]Select option selected keyword not working
在我的html中使用選擇選項下拉列表,但在我的Angular項目中不起作用
<td>
<select type="text" class="form-control" [(ngModel)]="addressDetails.AddressTypeId"id="AddressTypeId" formControlName="AddressTypeId" style="height:29px; width:200px; padding:3px">
<option disabled selected value > -- select an option -- </option>
<option *ngFor="let addressType of addressTypeDetails" value={{addressType.AddressTypeID}}>
{{addressType.AddressType}} </option>
</select>
</td>
您正在綁定數組對象的ngmodel,這是不正確的。 我創建了一個樣本的實例,請在檢查stackblitz我創建addressDetail對象與ngModel綁定。 請檢查以下html。 這是組件代碼。
addressTypeDetails = [{AddressTypeID:1,AddressType:'first'},{AddressTypeID:2,AddressType:'second'}]
addressDetail = {addressTypeId:0}
這是HTML代碼。
<select type="text" class="form-control" [(ngModel)]="addressDetail.addressTypeId" id="AddressTypeId" style="height:29px; width:200px; padding:3px">
<option > -- select an option -- </option>
<option *ngFor="let addressType of addressTypeDetails" value={{addressType.AddressTypeID}}>
{{addressType.AddressType}} </option>
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.