question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default values in multi-select async

See original GitHub issue

This is not a bug but a question I am trying to set default values in multi-select with async data source and it’s not working

my 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>

and 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     ;
   });
     }

Expected behavior I can find the selected users + search the backend to select users

Angular 6 ng-select 2.10.5

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
varnastadeuscommented, Oct 20, 2018
screenshot 2018-10-20 at 19 29 04

There is warning in console, if you want to set your model as object you should not use bindValue. Or if you want to use bindValue and object as model then define compareWith so ng-select could resolve your value by your predicate.

0reactions
gauravmasand09commented, Feb 14, 2021

Is this issue solved? because i cannot bind the data for async multiselect

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-select Async Multi-select : How to set default selected ...
Like this: <AsyncSelect isMulti cacheOptions loadOptions={promiseOptions} value={yourArray.map((item) => { return { value: item.value, ...
Read more >
Async - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
react-multi-select-component - npm
Prop Description Type labelledBy value for aria‑labelledby string options options for dropdown value pre‑selected rows
Read more >
Multiselect Element - Laraform
Basic Usage; Searchable; Custom Option; Async Options ... default, array, Value of element when the form is initially loaded or reseted.
Read more >
Select - WireUI Docs
How to Customize the async-data ; 6 'api' => route('api.users.index'), ; 7 'method' => 'POST', // default is GET ; 8 'params' =>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found