我有一个dropdown,我想要有一个默认的第一个空白元素,比如"select an option",当用户选择一个dropdown元素时,这个第一个字段就会消失。后来,在setInterval的帮助下,我试图清理我的下拉列表,不选择任何选项,并从一开始就看到下拉列表。我怎样才能做到这一点?这是我的代码。
//templates/home/home.component.html
<select [(ngModel)]='myselect' >
<option [value]="" selected >select and option</option>
<option *ngFor='let option of test' [value]="option.id">
{{option.nombre}}</option>
</select>
//components/home/home.component.ts
title = 'app';
myselect:any;
test:any= [{"id": "1", "nombre":"pedro" },{"id": "2",
"nombre":"yeison" }];
ngOnInit() {
this.timeoutFun();
}
timeoutFun() {
setTimeout(function(){
//clear my dropdown
this.myselect="";
}, 5000);
}
这是我的代码:
https://stackblitz.com/edit/angular-n8x7xo?file=src/app/templates/home/home.component.html
https://stackoverflow.com/questions/50728432
复制相似问题