I have array of data which includes array inside each item of it, so far i can show the exact data as I want except for id's.
Logic
- Show arrays in array
- Get arrays id (not arrays in array id
explanation in screenshot)
Screenshot
Information provided in image of what ID I need to have
Code
Controller
products: any[] = [];
limit = 10;
loading: any;
ngOnInit() {
this.getProducts();
}
async getProducts() {
this.loading = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
duration: 3000
});
await this.loading.present();
this.wishlistService.getProducts().subscribe((res) => {
console.log('res', res);
console.log('wishes', res['wishes']); // in screenshot you see this data
for (let wish of res['wishes']) {
this.products.push(wish.product);
}
this.hideLoading();
});
}
private hideLoading() {
this.loading.dismiss();
}
// For this function I need the upper ID (currently getting product ID I need wishlist item ID)
removeWishlist(id: string) {
console.log('product id for remove', id);
this.wishlistService.remove(id).subscribe(
data => {
this.alertService.presentToast(data['message']);
},
error => {
this.alertService.presentToast(error['message']);
}
);
}
View
<ion-row *ngIf="products.length>0 else noItem">
<ion-col size="6" class="prodCard" size-sm *ngFor="let product of products | slice:0:limit">
<img [src]="product.photo">
<h4 class="productTitle">
{{product.name}}
</h4>
<ion-row>
<ion-col size="9" size-sm>
Prices here
</ion-col>
<ion-col size="3" size-sm class="ion-text-center">
<ion-icon (click)="removeWishlist(product.id)" color="danger" name="heart"></ion-icon>
</ion-col>
</ion-row>
</ion-col>
</ion-row>
Any idea?
