Tanmay
Tanmay

Reputation: 7

onclick function not working when rendered in ts file (Angular 4 & ionic 3)

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

Answers (2)

Abhishek Gautam
Abhishek Gautam

Reputation: 1767

Use in this way : (click)="myFunction()"

Upvotes: 0

rikg93
rikg93

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

Related Questions