Reputation: 195
I want to trigger click
event based on each element id
but it is not working.
Here is my code:
ngOnInit() {
this.getProductsLists();
}
getProductsLists() {
this.supplierService.getProductLists()
.subscribe(data => {
this.productData = data;
this.productData.forEach((value) => {
value.prodCategoryChild.forEach((element) => {
$('#prod' + element.id).click(() => {
alert('This is not working');
})
});
});
});
}
What am I missing here? Thanks.
Upvotes: 1
Views: 1973
Reputation: 5574
An Angular way should be like this:
<div-or-whatever (click)="clickHandler(prod.id)" *ngFor="let prod of productData" >{{ prod.label }}</div-or-whatever>
then
clickHandler(id) {
alert(`Clicked prod ${id}`);
}
Upvotes: 1