user2516917
user2516917

Reputation: 383

Using ng-click to call two different functions

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()"

Upvotes: 38

Views: 70582

Answers (4)

Flash
Flash

Reputation: 185

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

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

Upvotes: 0

krekto
krekto

Reputation: 1487

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;

   });
};

Upvotes: 0

Sanjib Debnath
Sanjib Debnath

Reputation: 3785

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

ng-click = "search()";

Upvotes: 1

daCoda
daCoda

Reputation: 3845

You can call multiple functions with ';'

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

Upvotes: 86

Related Questions