Reputation: 7
Hey guys I want to know how to call a function while rendering html in .ts file.I have tried it my project, i am able to show the image tag but not able to call a function when clicked on the image..is their any other way to fix this?
commonFunctionActive(nullDataActive) {
console.log("NEWACCOUNTOPENING");
let str = "";
if (nullDataActive == "New Customer Active") {
str = '<img class="imgActiveCust" src ="assets/member_images/viewCustomer.jpg" onclick="myFunction()" alt="">';
} else {
str = nullDataActive
}
return (str);
}
myFunction() {
console.log("customererrrrererer");
let self = this;
if (self.nullDataActive.customer_id != "") {
self.navCtrl.push("CustomerPage");
}
else {
}
}
Upvotes: 0
Views: 406
Reputation: 1269
Your error is simple: you're using onclick, but in angular 2+ you should use (click)="myFunction()"
Read more at MDN:
Upvotes: 1