Search code examples
javascriptangularjsangularjs-ng-click

Multiple function invoked from ng-click also using lazy evaluation


I've managed to disable ngClick on an element if a variable assigned to the scope (notInProgress) evaluates to true like so:

<a data-ng-click="notInProgress || $ctrl.setTab('renewal');</a>

I need to now add further function to be invoked based on the variable like so:

<a data-ng-click="notInProgress || $ctrl.setTab('grantandpublishing'); 
                  notInProgress ||  activeLeft = 4;">
</a>

I've tried the above but it keeps returning an error:

Error: $parse:lval Trying to assign a value to a non l-value

Question

How do I add multiple functions to ngClick that are disabled if notInProgress evaluates to true?


Solution

  • You can move that code into single function like below.

    <a data-ng-click="process($ctrl)"></a>
    
    $scope.process = function($ctrl) {
    
       if (!$scope.notInProgress) {
             $ctrl.setTab('grantandpublishing');
              $scope.activeLeft = 4;
        }
    }
    

    So that you can call as many as functions inside that function. Hope this helps. Let me know for any further help.