simply I want to run a function on click only when certain condition exists , I don't need to add extra function in component ts file to check for the condition , I need to do it inline, like
<button (click)="'condition==true'?runFunction()">
simply I want to run a function on click only when certain condition exists , I don't need to add extra function in component ts file to check for the condition , I need to do it inline, like
<button (click)="'condition==true'?runFunction()">
You can do that by creating the function inside the component.ts
check(){
if(condition){
callThatFunction();
}
}
and in HTML
<button (click)="check()">
As @Sajeetharan noted, its best to do the check inside your controller. If its not suitable for you, you could also have 2 buttons in your template, like this:
<button *ngIf="condition" (click)="runFunction()">
<button *ngIf="!condition">