HTML:
<select (focus)="onFocus()">
<option *ngFor="let c of myDropDown">{{c}}</option>
</select>
<input [hidden]="myDropDown !=='two'"type="text">
Component:
onFocus() {
this.http.get('https://jsonplaceholder.typicode.com/posts').subscribe(val => {
console.log(val)
this.myDropDown = val;
})
}
在选择焦点上,我试图通过拨打服务电话来获取选项,但不知何故下拉菜单没有打开,我必须点击两次。
StackBlitz 链接: https ://stackblitz.com/edit/angular-select-example-3jvz1h?file=app%2Fapp.component.ts