Trying to bind data to a drop-down menu, but not bind anything, drop-down displays NOTHING selected.
<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>
Angular Code:
getClassificationTypes(): void { //need to remove hard coding this._commonService.getLookupItems(1, 6).subscribe((result) => { this.classificationTypes= result.items; }); } ngOnInit(): void { this.getClassificationTypes(); }
When I try to debug the code, classificationTypes has the corresponding data, the same data that I used as a hard-coded value. It works great.
The getClassificationTypes method calls the API to retrieve data from the database.
I am writing this application using the ASP.NET Zero framework.
I tried the solution below. it is data binding to a drop-down list, but there is no automatic search function in the drop-down list, and it shows a simple drop-down list. and in the console it gives the following error message.
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
in the console log, classificationTypes displayed as [classType, classType, classType, classType ]
Answer from 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}