Home > Software design >  How can I call a function when clicked on a button?
How can I call a function when clicked on a button?

Time:09-16

Basically I have just started MEAN stack

I want to call a function on a button click this is what I am trying to do :

this is my html file

<button (click = func())>Click here!</button>

this is my .ts file

func(){
console.log("called a function on a button click")
}

your help will mean me a lot!

CodePudding user response:

There is an issue in your html while binding click event.

Try below code:

<button (click)="func()">Click here!</button>

CodePudding user response:

<button (click)="func()">Click here!</button>


func(){
console.log("called a function on a button click")
}

this should work for you

  • Related