【发布时间】:2018-07-16 12:33:21
【问题描述】:
尝试将数据绑定到下拉菜单,但不绑定任何内容,下拉菜单显示 没有选择。
<select #classProductTypeCombobox
name="classProductTypeCombobox"
class="form-control col-md-3"
[(ngModel)]="classification.codeType"
[attr.data-live-search]="true"
jq-plugin="selectpicker"
required>
<option *ngFor="let classType of classificationTypes"
[value]="classType">{{classType}}</option>
</select>
角度代码:
getClassificationTypes(): void {
//need to remove hard coding
this._commonService.getLookupItems(1, 6).subscribe((result) => {
this.classificationTypes= result.items;
});
}
ngOnInit(): void {
this.getClassificationTypes();
}
当我尝试调试代码时,classificationTypes 具有正确的数据,与我用作硬编码值的数据相同。它工作正常。
方法getClassificationTypes正在调用API从数据库中获取数据。
我正在使用 ASP.NET Zero 框架编写这个应用程序。
我尝试了以下解决方案。这是将数据绑定到下拉列表,但下拉列表的自动搜索功能消失了,它显示的是简单的下拉列表。并在控制台中给出以下错误消息。
getClassificationTypes(): any {
return this._commonService.getLookupItems(2, 6).subscribe((result) => {
console.log(result.items)
return this.classificationTypes = result.items;
});
}
classificationTypes: TaxonomyItemsLocDto[] = this.getClassificationTypes();
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
在控制台日志中classificationTypes 显示为[classType, classType, classType, classType ]
来自 API 的响应:
{"result":{"items":[{"taxonomyItemsId":4,"taxonomyMasterId":2,"taxonomyItemLocDesc":"Sales"},{"taxonomyItemsId":5,"taxonomyMasterId":2,"taxonomyItemLocDesc":"Administrative"},{"taxonomyItemsId":6,"taxonomyMasterId":2,"taxonomyItemLocDesc":"Financial"},{"taxonomyItemsId":7,"taxonomyMasterId":2,"taxonomyItemLocDesc":"Informative"}]},"targetUrl":null,"success":true,"error":null,"unAuthorizedRequest":false,"__abp":true}
【问题讨论】:
标签: angular typescript angular2-template