1

I am trying to use a multi-select dropdown with an array of arrays but it doesn't seem to work.

The html is:

<ng-multiselect-dropdown [placeholder]="'Schools'" [settings]="transcriptSettings"
  [data]="selectedInstitutions" [(ngModel)]="abbreviation.institutionIds">
</ng-multiselect-dropdown>

The data is selectedInstitutions which has 2 records but doesn't work If I changed it to another array (institutionIds), it displays correctly. The difference seems to be that in the debugger the one that doesn't work says "Array" and the one that does work says "{...}. Not sure why that is an issue.

Why are they different?

enter image description here

Looking at them drilled down is:

enter image description here

In DevTools, institutionList which works is an array of objects and the selectInstitutions is an array of arrays.

enter image description here

Thanks,

Tom

1
  • Would be better if you can provide the data as snippet, instead of images. Commented Feb 1, 2022 at 4:39

1 Answer 1

1

According to ng-multiselect-dropdown (Setting section),

Setting Type Description
data Array Array of items from which to select. Should be an array of objects with id and text properties

Solution

Hence, flatten the array of arrays to an array of objects.

this.selectedInstitutions = [].concat(...this.selectedInstitutions);

Sample Demo on StackBlitz

Sign up to request clarification or add additional context in comments.

3 Comments

Is that why this doesn't work: this.tempArray = this.selectedInstitutions.map(x => { return { id: x.id, displayValue: x.displayValue } });
Hi, selectedInstitutions is with the value of array of arrays? If yes, then you can't do in the map way, you have to flatten the array first. Would be better if you can provide the value of selectedInstitutions. Thanks.
That did it.. Was able to map after it was flattened. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.