I have following part of code.
var app = angular.module('app', []);
app.controller('DemoCtrl', function($scope, accessService) {
$scope.isPageAccessible = function(pageCode) {
return accessService.checkAccess(pageCode);
};
});
app.factory('accessService', function(){
var availableRoles = ['PROFILE'];
var service = {};
service.checkAccess = function (role) {
console.log('Check role: ' + role);
return availableRoles.some(function (element) {
return element == role;
});
};
return service;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<ul class="nav nav-tabs" ng-app="app" ng-controller="DemoCtrl">
<li class="active"><a href="#">Home</a></li>
<li><a ng-show="isPageAccessible('PROFILE')" href="#">Profile</a></li>
<li><a ng-show="isPageAccessible('MESSAGE')" href="#">Messages</a></li>
</ul>
And I surprised why angular call function isPageAccessible() multiple times. In my mind function isPageAccessible() should be called only twice, but in the concole I see 4 calling. If somebody know why?