Surjeet Bhadauriya Surjeet Bhadauriya - 3 months ago 16
Javascript Question

Is there a drawback of calling more than one function in a ng-click directive?

We are calling two functions in a single ng-click directive, is there any gotcha that we should be aware of?

<button type="button" ng-click="func1(); func2();">Click</button>


We could also call a single function that calls the two function instead:

<button type="button" ng-click="func1()">Click</button>

$scope.func1(){
func2();
}

$scope.func2(){
//something
}

Aan Aan
Answer

No, there is no drawback of calling more than one function inside ng-click, but we have to ignore it most of the time because it's not good practice.

You can achieve this by calling a function inside another function.

<button type="button" ng-click="func1(); func2(); func3();">Click</button>

So here func1 will call first, then func2 and func3.

Comments