YoniGeek YoniGeek - 2 years ago 85
Javascript Question

How to add many functions in ONE ng-click?

Ive be looking for how to execute this but I can't find anything related so far, :(
I could nest both functions yes but Im just wondering if this is possible?
I'd like to do this literally:

<td><button class="btn" ng-click="edit($index) open()">Open me!</button></td>

My JS code at the moment:

$scope.open = function () {
$scope.shouldBeOpen = true;

$scope.edit = function(index){

var content_1, content_2;
content_1 = $scope.people[index].name;
content_2 = $scope.people[index].age;


I'd like to call two functions with just one click, how can I do this in angularJS?
I thought it'd be straight forward like in CSS when you add multiple classes...but it's not :(

Thanks for yr time

Answer Source

You have 2 options :

  1. Create a third method that wrap both methods. Advantage here is that you put less logic in your template.

  2. Otherwise if you want to add 2 calls in ng-click you can add ';' after edit($index) like this

    ng-click="edit($index); open()"

See here : http://jsfiddle.net/laguiz/ehTy6/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download