1

我正在尝试使用异步数据源在多选中设置默认值,但它不起作用

我的 HTML

<ng-select 
  style="padding-top: 10px" [items]="users | async" 
  [virtualScroll]="true" bindLabel="name" bindValue="id" placeholder="إختر 
  موظف" [loading]="usersLoading" (add)="addUser($event)" [multiple]="true" 
  [typeahead]="usersinput$" [(ngModel)]="selectedUser"> 
</ng-select>

和 TS

comp: any;
  submitted: boolean;
  EditCompanyForm: FormGroup;
  errors: any;
  logo: any;
  uploadLogo: any;
  progress:any;
  selectedUser:User[];
  users:any;
  usersinput$ = new Subject<string>();
  usersLoading = false;

 ngOnInit() {
    this.loadusers();
 this.getComapny();
}
getComapny() {
    const id = +this.route.snapshot.paramMap.get("id");
    this.companyService.getCompany(id).subscribe(res => {
      this.assignCompany(res);
    });
  }
 assignCompany(data) {
    this.comp = data;
    let u=this.comp.employees.map(a=>a.user);
//here where I am trying to assign the default values
    this.selectedUser= u     ;
   });
     }

预期行为我可以找到选定的用户+搜索后端以选择用户

Angular 6 ng-select 2.10.5

4

0 回答 0