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.
*ngForin your template and bind to the click event of each item and pass the id or index as an argument to the function that you'll be calling as your click handler.