2017-08-15 76 views
0

我有一個服務的提取關鍵字,我用ngFor來顯示這些關鍵字作爲標籤。但我得到這個上面的錯誤找不到類型爲'object'的不同支持對象'[object Object]'。 NgFor只支持綁定到Iterables如陣列離子2

這裏是代碼

<ion-content> 
    <ion-searchbar [(ngModel)]="myInput" [showCancelButton]="shouldShowCancel" (ionInput)="onInput($event)" (ionCancel)="onCancel($event)"> 
    </ion-searchbar> 
    <ion-card *ngIf="suggest"> 
    <ion-card-header> 
     Suggestions 
    </ion-card-header> 
    <ion-card-content> 
     <ion-badge *ngFor="let item of keyword;" > {{item.keyword}}</ion-badge> 
    </ion-card-content> 

這是我打電話的時候,

onInput(event) { 
    this.suggest = true; 
    this.keywords = this.logins.getkeywords(this.myInput).subscribe((data) => this.keywords = data) 


    } 

,這裏是該服務的搜索服務

​​

}

這裏是服務器響應

[{"keyword":"asd"},{"keyword":"aptitude"},{"keyword":"arrangements"},{"keyword":"averages"},{"keyword":"aadasda"},{"keyword":"asdasd"},{"keyword":"anesthesiology"},{"keyword":"asds"}] 

回答

0

我得到了解決方案,這是我被服務調用引起的。

onInput(event) { 
    this.suggest = true; 
    this.keywords = this.logins.getkeywords(this.myInput).subscribe((data) => this.keywords = data) 


    } 

在這裏,我在兩個地方指定數據的關鍵字一次當我收到的數據,一旦當我致電服務,使其正確,然後獲取數據再次分配的用戶對象將其造成的錯誤。

相關問題