'get all the data from ng-select's observable items
I am planning to add select all for the ngSelect where my ng-select is similar to this
<ng-select formControlName="filterValue" [items]="filterValues | async"
[typeahead]="filterValuesInput"
[multiple]="true"
(open)="getFilterValues(pref.id)"
[loading]="filterValuesLoading"
bindLabel="name"
bindValue="id">
</ng-select>
I am calling the backend to get the relevant data as per the user's input using typeahed. I am calling selectAll by putting button in ng-select's header
<ng-template ng-header-tmp>
<button (click)="selectAll('filterValue', filterValues)">Select all</button>
</ng-template>
my selectAll method is like this
selectAll(formParam: string, list: any) {
if(formParam === 'filterValue') {
let orgs:Organization[] = [];
list.subscribe(org =>{
orgs =[...org]
})
this.myForm.get(formParam).setValue(orgs.map(option => option.id));
}
else {
this.myForm.get(formParam).setValue(list.map(option => option.id));
}
}
I am getting 'orgs null even though I can see data on ng-select list in UI.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
