Reputation: 363
I have 2 selects:
<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>
What should i add to onChange($event) to set the documentTypeSelect option to "Select..." everytime i change something in the first select? Something like this.documentTypeSelect = ???
Upvotes: 0
Views: 1280
Reputation: 657148
Change
<option [ngValue]="undefined"
to
<option [ngValue]="''"
If you then set companySelect
to ''
this option will be selected
companySelect:string = '';
For more complicated scenarios, see also Angular 2 Dropdown Options Default Value
Upvotes: 1