Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-select : selectedItems.map is not a function

When I'm using ng-select in reactive form angular I get this error:

ERROR TypeError: selectedItems.map is not a function

I have 3 select the first two work very well but in this third one I get the error ! to map item i'm using the function (the ng-select is inside *ngFor) :

//for mappinig item : 
mapLabelValueBS(objet) {
return objet.map(data => {
 return {
   id: data,
   text: data.name
 }
})
}
//this is the one that is causing the problem
<ng-select 
  [allowClear]="true"                                                 
  [items]="mapLabelValueBS(filieres)"
  placeholder="Filière non sélectionné"                                             
  (selected)="selecteFiliere($event)"                                                     
  formControlName="filiere">
</ng-select>

the result in my page (when I click on the field it doubles itself) :

enter image description here

like image 298
hamwac5 Avatar asked Sep 09 '26 10:09

hamwac5


1 Answers

This error came while I was passing [items]="value" where the value was not an array, so please check if you are not passing non array element to items binding.

like image 186
d1fficult Avatar answered Sep 10 '26 23:09

d1fficult



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!