i am getting this error "ERROR Error: Error trying to diff 'true'. Only arrays and iterables are allowed"
i am getting this error "ERROR Error: Error trying to diff 'true'. Only arrays and iterables are allowed"
试图将数据从 ts 显示到 angular 中的 Html 模板,但我收到此错误 "ERROR Error: Error trying to diff 'true'. Only arrays and iterables are allowed"
我认为它告诉我我传递的数据不是数组!如果你们知道如何解决这个问题,我们将不胜感激
看看我的代码
public products: any =[];
constructor( public navCtrl: NavController,
public http: HttpClient,
public nativeHttp:HTTP,
public plt:Platform,
public loadingCtrl:LoadingController,
public popoverCtrl: PopoverController
) {
this.getData();
}
async getData(){
let loading = await this.loadingCtrl.create();
await loading.present();
this.http.get('https://gratisgospel.net/APIproducts').pipe(
finalize(()=> loading.dismiss())
)
// .map(response => response.json().data)
.subscribe(data => {
console.log('native data',data);
this.products = JSON.stringify({data});
// this.products = Array.of(this.products);
// this.products = data;
if (this.products=!'') {
// code...
console.log('data are available');
}
});
在我的 HTML 中,这是我要使用循环显示数据的文件
<ion-col offset="1" *ngFor="let product of products">
<div class="box">
<img class="" src="../assets/imgs/air-zoom-pegasus-36-tortoise-shell-womens-running-shoe-ksw5Hx.jpg">
<h2 class="ion-text-center">nike Air</h2>
<ion-grid>
<ion-row>
<ion-col offset="1">
<ion-icon name="ios-pricetag" padding></ion-icon>
</ion-col>
<ion-col offset="1">
detail
</ion-col>
</ion-row>
</ion-grid>
<div>
</div>
</div>
</ion-col>
当您没有将数组传递给 ngFor
指令时,会出现此错误。
请确保您的产品对象是数组类型。
PS - 您还可以使用 KeyValuePipe
迭代对象:
https://angular.io/api/common/KeyValuePipe
谢谢你们,根据您的指导,我想出了解决问题的方法,只是创建了一个数组并推送了数据,然后 boom 问题就解决了!
试图将数据从 ts 显示到 angular 中的 Html 模板,但我收到此错误 "ERROR Error: Error trying to diff 'true'. Only arrays and iterables are allowed"
我认为它告诉我我传递的数据不是数组!如果你们知道如何解决这个问题,我们将不胜感激
看看我的代码
public products: any =[];
constructor( public navCtrl: NavController,
public http: HttpClient,
public nativeHttp:HTTP,
public plt:Platform,
public loadingCtrl:LoadingController,
public popoverCtrl: PopoverController
) {
this.getData();
}
async getData(){
let loading = await this.loadingCtrl.create();
await loading.present();
this.http.get('https://gratisgospel.net/APIproducts').pipe(
finalize(()=> loading.dismiss())
)
// .map(response => response.json().data)
.subscribe(data => {
console.log('native data',data);
this.products = JSON.stringify({data});
// this.products = Array.of(this.products);
// this.products = data;
if (this.products=!'') {
// code...
console.log('data are available');
}
});
在我的 HTML 中,这是我要使用循环显示数据的文件
<ion-col offset="1" *ngFor="let product of products">
<div class="box">
<img class="" src="../assets/imgs/air-zoom-pegasus-36-tortoise-shell-womens-running-shoe-ksw5Hx.jpg">
<h2 class="ion-text-center">nike Air</h2>
<ion-grid>
<ion-row>
<ion-col offset="1">
<ion-icon name="ios-pricetag" padding></ion-icon>
</ion-col>
<ion-col offset="1">
detail
</ion-col>
</ion-row>
</ion-grid>
<div>
</div>
</div>
</ion-col>
当您没有将数组传递给 ngFor
指令时,会出现此错误。
请确保您的产品对象是数组类型。
PS - 您还可以使用 KeyValuePipe
迭代对象:
https://angular.io/api/common/KeyValuePipe
谢谢你们,根据您的指导,我想出了解决问题的方法,只是创建了一个数组并推送了数据,然后 boom 问题就解决了!