A method that returns href in ng-href called contineously

I have a menu widget in which each menu item can expand into another submenu. Something similar to this: http://plnkr.co/MGqCkAFUexSzSfcwthu5?p=preview

Link markup:

<a class="link-class"
    ng-href={{ getLink(item) }}
    ng-style="setTextAlignment(level)">
    {{ item.name }}
 </a>

Using the following method defined in the controller:

 /**
 * @param {!angular.Scope} scope The scope of the directive.
 * @param {!Object} item The menuitem.
 * @return {string} Whether current user can access item.
 * @private
 */
 CollapsibleSubMenu.getLink_ = function(scope, item) {
   console.log('link called');
   return item['subMenu'] ? '' : item['link'];
 };

Basically, if an element has a submenu (submenu === true), it should not have href (but the data from the backend elements have elements with a submenu: true and a valid link. This was good for the old menu implementation.)

, , , , console.log " " . . , getLink ?

+4
1

Angular , , , $digest, , , .

, , , , .

angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope){
  var numCalls = 0;
  
  $scope.getConstantValue = function(){
    numCalls += 1;
        
    return "Never gonna change";
  };
  
  $scope.getNumberOfCalls = function(){
    $scope.numCalls = numCalls;
  };
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <input type="text" ng-model="myInput" />
  <p>Number of calls: {{numCalls}}</p>
  <p>{{getConstantValue()}}</p>
  <button type="button" ng-click="getNumberOfCalls()">Update Call Count</button>
</div>
Hide result
+2

All Articles