Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From html file call a function based on condition without using *ngIf

Tags:

angular

I want to call 2 functions in a single <input type="text" (focusout)=""> based on a condition. I don't want to use *ngIf else conditions.

Example
component.ts file i have declared 1 variable like

isCall = true;     
functionA(){}
functionB(){}

My component.html file is as follow

<input type="text" (focusout)="">

I want to call these 2 functions based on isCall from (focusout)="" event.
Suppose isCall variable is true then I want to call functionA() else functionB()
How can I call these function based on the condition?

like image 437
Bhagwat Tupe Avatar asked Oct 26 '25 10:10

Bhagwat Tupe


2 Answers

You can call two functions by using ternary operator based on condition.

<input type="text" (focusout)="isCall ? functionA() : functionB() ">

Here is solution on stackblitz

like image 129
Sandy Sanap Avatar answered Oct 29 '25 00:10

Sandy Sanap


You can use ternary operator ? : and based on condition you can call functionA() or functionB() like below.

component.html

<input type="text" (focusout)="isCall ?  functionA() : functionB()">

component.ts

 functionA() {
    console.log('HelloA');
  }

   functionB() {
    console.log('HelloB');
  }

Here is solution on stackblitz

Hope this will help!

like image 26
TheParam Avatar answered Oct 28 '25 23:10

TheParam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!