38

Is there a way I can get ng-click to call two functions?

I would like something along the lines of

ng-click ="{search(),match()}" 

Instead of how I have it now, which is:

ng-click = "search()"
1

4 Answers 4

86

You can call multiple functions with ';'

ng-click="search(); match()"
Sign up to request clarification or add additional context in comments.

2 Comments

are you sure? That doesn't seem to work for me EDIT: Nvm, its actually ng-click="search();match()" Thanks for leading me to the right answer!
You can do it, however this is not best practice. e.g if you are passing events through, something can kill the second function so it will never execute. This way is possible but not best practice.
1

Please use search() one function and add a callback function of match() inside search() function;

ng-click = "search()";

Comments

0

using the ng-click to call function:

ng-click="search()"

using the callback approach if function search () depends on the value returned by function math () in the controller do:

$scope.match() = function(cb){

//do something and return value
        var x = 10;
        x = x+10;

cb(x)

};

$scope.search() = function(){

   //call math function 
   $scope.match(function(value){

   myCalc = value;

   });
};

Comments

0

You can use multiple methods with (click) separated by ;

(click)="search();match()"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.