Search code examples
angularjsangularjs-ng-click

calling two different functions using ng-click


I am trying to call two different functions using ng-click="Reset();Search()" But it isn't working. Is this the correct way of using ng-click for multiple functions?


Solution

  • Your html should look something like this (vm for 'controller'):

    <a ng-click="vm.multipleMethodCalls()">link text</a>
    

    Your controller should have the method (ES5 code style) which calls two other (or more if you want) methods:

    function multipleMethodCalls() {
      this.Reset();
      this.Search();
    }
    

    What you do NOT want to do is litter the templates with more and more code and logic. Remember the saying 'KISS', Keep It Simple Stupid, the simpler the better. Moving your logic into the controller is easy to understand and allows you a little more control.