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

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

我正在尝试为角度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选项设置默认对象。

angular typescript angular6
1个回答
1
投票

设置组件的默认值

constructor(){
  this.updateModel.userType = ""
}
© www.soinside.com 2019 - 2024. All rights reserved.