简体   繁体   中英

Default “placeholder” of Select-box in Angular?

I'm developing a web application (front-end size) using Angular 6. I have a question: I'm creating a component that contains different select-box, like this:

在此处输入图片说明

How can I create a reset() method that changes all the select-box with the placeholder value (without canceling or modifying the options associated with him in any way)? Is there any way that allows this by modifying the html template programmatically? Thanks!

you can use ngModel

 <select class="custom-select" [(ngModel)]="model.select"  name="select" id="combo">
      <option value=""></option>
      <option *ngFor="let item of list" [ngValue]="item">{{ item}}</option>
 </select>

component:

reset(){
   model.selct='';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM