Reputation: 453
I know that we can give multiple classes in class directive by giving one space after declaring a class.In the same way can we write multiple passing elements and calling functions in the ng-click directive?
Upvotes: 2
Views: 640
Reputation: 685
You have 2 options :
Create a third method that wrap both methods. Advantage here is that you put less logic in your template.
Otherwise if you want to add 2 calls in ng-click you can add ';' after method1('test') like this
ng-click="method1('test'); method2('first','second');"
See here : http://jsfiddle.net/banshi/5kwn0an8/3/
Upvotes: 3
Reputation: 41417
Yes you can. separate two functions by semicolon
<div ng-click="functionOne();functionTwo()"> </div>
angular.module("app", [])
.controller("ctrl", function($scope) {
$scope.functionOne = function() {
console.log("functionOne")
}
$scope.functionTwo = function() {
console.log("functionTwo")
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-click="functionOne();functionTwo();"> click</div>
</div>
Upvotes: 1
Reputation: 39
You can use the following code to call multiple functions at a time
<button ng-click="method1(); method2();">
Submit
</button>
Upvotes: 2