我有两个选择:
<form name="newDocumentForm">
<label for="companySelect"> Company: </label>
<select name="companySelect" id="companySelect" [(ngModel)]="companySelect"
(ngModelChange)="onChange($event)">
<option [ngValue]="undefined" disabled selected>Select...</option>
<option *ngFor="let company of companies" [ngValue]="company">{{company.name}}</option>
</select>
<label for="documentTypeSelect"> Type: </label>
<select name="documentTypeSelect" id="documentTypeSelect"
[(ngModel)]="documentTypeSelect">
<option [ngValue]="undefined" disabled selected>Select...</option>
<option value="aaa">ty</option>
<option value="bbbb">ew</option>
</select>
</form>
每当我在第一个选择中更改内容时,我应该在onChange($ event)中添加什么来将documentTypeSelect选项设置为“Select ...”? 像this.documentTypeSelect = ???
这样的东西答案 0 :(得分:1)
更改
<option [ngValue]="undefined"
到
<option [ngValue]="''"
如果您将companySelect
设置为''
,则会选择此选项
companySelect:string = '';
对于更复杂的方案,另请参阅Angular 2 Dropdown Options Default Value