How to autoselect items coming from an api in ng-multiselect-dropdown when the component loads?

197 views Asked by At

I am using ng-multiselect-dropdown in my angular project as below:

<ng-multiselect-dropdown  [settings]="dropdownSettings" [data]="empList" [(ngModel)]="emp_id"
                         (onSelect)="onItemSelect($event)" 
                        (onDeSelect)="onItemDeSelect($event)" (onDeSelectAll)="onUnSelectAll($event)" >
                    </ng-multiselect-dropdown>

And below is the dropdownSettings:

this.dropdownSettings = {
            idField: 'Employee_Number',
            textField: 'Name',
            allowSearchFilter: true
          };

Since empList contains the list of all employees name and id, these are coming in the dropdown. onSelect, OnDeSelect and OnDeSelectAll functions are working fine.

In onSelect function, I am pushing all the selected items in an array emp_id and saving the itemsd in the database on click of submit button of webpage.

Right now, I am facing issue in autoselecting the items which are saved in the database( and coming from the api) when the component loads. I have figured out that [(ngModel)] is not working in ng-multiselect-dropdown.

Please do help in this case. Thanks in advance.

0

There are 0 answers