0

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.

  • What do you mean ngModel is not working, please provide the code where you define emp_id and the api call from database, where you try to set the preselection – MoxxiManagarm Nov 15 '22 at 12:59
  • It is not working because you are binding emp_id. Also your settings mentioned idField as "Employee_Number". Looks like you have not integrated it properly. Create stackblitz demo or refer this: https://www.npmjs.com/package/ng-multiselect-dropdown – Devang Patel Nov 15 '22 at 13:16

0 Answers0