我将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的选择