【发布时间】:2019-10-14 11:11:08
【问题描述】:
我对后端进行 api 调用以填充下拉列表,并且它可以工作。但问题是,只有当用户在下拉列表上单击两次时,数据才会显示在下拉列表中。但是在控制台中,当我单击下拉列表一次时,我看到数据已加载。
所以我尝试使用 setTimeout。但这不起作用。
这是 api 调用:
getQrCodes() {
setTimeout(() => {
this.returnQrCodes$ = this.qrCodeDefinitonService.getDefinitionForSelection()
.pipe(tap(console.log));
}, 1000);
}
这是模板:
<div class="search-select searchoptions"
*ngIf=" selectedSearch && hasOtherOptions(selectedSearch)">
<mat-select placeholder="Opties" name="option"
[(ngModel)]="selectedValueOptie" (click)="getQrCodes()">
<mat-option *ngFor="let option of (returnQrCodes$ | async)"
value="option.value"> {{ option.qrCode }} </mat-option>
</mat-select>
</div>
所以我的问题是:如果你只点击一次,如何在下拉列表中显示数据?
谢谢
【问题讨论】:
标签: javascript angular observable settimeout