如何将加载的数据正确绑定到@ ng-select,angular6

时间:2018-10-04 03:58:56

标签: html angular typescript angular-ngselect

我将ng-select与异步列表一起使用,我不知道如何绑定所选对象

<ng-select formControlName="traLoiMaVanBan"
    [items]="lstVanBanDen$ | async"
    bindLabel="text"
    bindValue="value"
    [hideSelected]="true"
    [loading]="documentloading"
    [typeahead]="documentinput$"
    [(ngModel)]="model.traLoiMaVanBan">
</ng-select>

TS代码:

documentloading: boolean = false;
  lstVanBanDen$: Observable<any[]>;
  documentinput$ = new Subject<string>();

 private loadIncommingDocument(value:string) {
    this.lstVanBanDen$ = concat(
      of([]), // default items
      this.documentinput$.pipe(
        startWith(value),
        debounceTime(200),
        distinctUntilChanged(),
        tap(() => this.documentloading = true),
        switchMap(term => this._service.suggestIncommingDocument({ keyword: term }).pipe(

          catchError(() => of([])), // empty list on error
          tap(() => this.documentloading = false)
        ))
      )
    );
  }

ngOnInit() {

    this.createFormDocument();
    this.loadIncommingDocument("");
    this.getInfoOutDocument();
  }

this._service.getInfoOutDocument(request).subscribe(data => {
this.model = data;
      if (this.model.traLoiMaVanBan != null) {
        this.loadIncommingDocument(data.traLoiVanBanInfo.text);
      }
      this.rebuildFormDocument();
    });

data.traLoiVanBanInfo is an object like {value:1,text:"Something"}

如何使用this.model.traLoiMaVanBan = data.traLoiVanBanInfo.value设置ng-select的选择

0 个答案:

没有答案