0

我使用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"}

我如何为 ng-select 设置选择this.model.traLoiMaVanBan = data.traLoiVanBanInfo.value

4

0 回答 0