我有一个角度材质选择组件,我想将下拉列表的选定值绑定到firebase的一个Observable of
scalar.我想在不打开组件中的observable的情况下这样做.它看起来我无法使用异步管道绑定值.下面的代码抛出一个异常,因为mat-select的值不能绑定到“uiStateSvc.currentClient $| async”.
@H_301_8@<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); } }) );