我有一个角度材料选择组件,我想将下拉列表的选定值绑定到来自 firebase 的标量 Observable。我想在不打开组件中的 observable 的情况下做到这一点。看起来我无法使用异步管道绑定值。下面的代码会抛出异常,因为 mat-select 的值不能绑定到“uiStateSvc.currentClient$ | async”。
<mat-form-field *ngIf="(store.authorizedClients$ | async)?.length > 0">
<mat-select [(value)]="uiStateSvc.currentClient$ | async" [compareWith]="compareFn">
<mat-option *ngFor="let client of store.authorizedClients$ | async" [value]="client"
(onSelectionChange)="changeCurrentClient($event, client)">
{{ client.name}}
</mat-option>
</mat-select>
</mat-form-field>
我正在从 firebase 中提取下拉列表的当前选定值,如下所示:
this.selectedClient$ = this.authSvc.currentUser$.pipe(
switchMap((x: firebase.User) => {
if (x != null) {
return this.afs.doc(`uistate/${x.uid}`).valueChanges().map((y: any) => y.selectedclient);
} else {
return Observable.of(null);
}
})
);