簡體   English   中英

在Angular 4中與ngModel綁定的一種方法不適用於Observables

[英]One way binding with ngModel in angular 4 it is not working with Observables

在此處輸入圖片說明 ] [1]
我有一個用Observables聲明的數組,該數組在console.log中顯示,但是在下拉列表中,我只能看到單擊下拉列表下方的ID或名稱,但是如果一個該對象包含一個字符串,該字符串應在下拉菜單中顯示給我,例如該項目下面的字符串32323,它負責該項目,當我打開該項目時,應該在下拉菜單中顯示該字符串。 這是我的代碼。

 cluster$: Observable<DropdownOption[]>;

 selectClusterOptions = createSelector(
    selectClusters,
    clusters => {
      const options: DropdownOption[] = [];
      options.push(...clusters.map(cluster => ({ key: cluster.id, value: cluster.name })).toArray());
      return options;
    }
  );


   this.cluster$ = store.pipe(select(this.selectClusterOptions));

這是HTML

<app-dropdown label="Cluster" labelWidth="75px" optionWidth="170px" [items]="cluster$ | async" [ngModel]="(selectValueItem$ | async).clusterId"></app-dropdown>

為了進行2種方式的綁定,您必須使用[(ngModel)]

<app-dropdown label="Cluster" labelWidth="75px" optionWidth="170px" [items]="cluster$ | async" [(ngModel)]="(selectValueItem$ | async).clusterId"></app-dropdown>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM