如何在角度6中为选择选项设置默认的选定对象

时间:2019-01-24 05:45:15

标签: angular typescript angular6

我正在尝试将默认选择对象设置为角度6中的选择选项,但是它不起作用

<select name="editUserType" class="form-select" id="editUserType" [(ngModel)]="updateModel.userType">
    <option value="" selected disabled>Select User Type</option>
    <option *ngFor="let userType of userTypeList"  [selected ]="userType.code == updateModel.userType.code"  [ngValue]="userType">{{userType.description}}</option>
</select> 

userType是我想要的对象,当我加载网页时,将默认对象设置为select选项。

1 个答案:

答案 0 :(得分:1)

设置组件的默认值

constructor(){
  this.updateModel.userType = ""
}