javascript - Angular ng-select : selectedItems. map 不是函数

标签 javascript angular angular4-forms angular-ngselect

当我以 react 形式使用 ng-select angular 时,出现此错误:

ERROR TypeError: selectedItems.map is not a function

我有 3 个选择,前两个工作得很好,但在第三个中我得到了错误!映射我正在使用该函数的项目(ng-select 在 *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>

我页面中的结果(当我点击该字段时它自身翻倍):

enter image description here

最佳答案

这个错误是在我传递 [items]="value"时出现的,其中值不是数组,所以请检查你是否没有将非数组元素传递给项目绑定(bind)。

关于javascript - Angular ng-select : selectedItems. map 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54709527/

相关文章:

node.js - 错误! Windows_NT 10.0.10586

angular - 排序后 Material 表上的可扩展行不起作用

angular - 如何以0/1而不是true/false react 形式获取复选框的值 Angular4

javascript - 将 props 发送到 @react-navigation/drawer 组件

angular - 测试组件方法调用另一个方法

javascript - Angular4 - 没有表单控件的值访问器

Angular 4获取管道的 react 形式输入值

javascript - 在 RxJS 中链接 Observable

javascript - Express & Handlebars 的全局属性

javascript - 如何创建可以链接在一起的函数?