I need an isLoggedIn() function that both controllers and templates all have access to (templates need it in order to do something like ng-show="isLoggedIn()"). What's the best way to do this?
If the answer is a service, then is it possible to access a service from within a template, or does each of my controllers need to create a wrapper function for the template to see it (in $scope)?
I usually have a 'MainCtrl' in my body tag and put global stuff in it.
<body ng-controller="MainCtrl">
...
</body>
function MainCtrl($scope, authService) {
$scope.isLoggedIn = function() {
return authService.isLoggedIn();
}
}
Then every other scope will inherit the isLoggedIn function.
You can also put the isLoggedIn on the $rootScope, but I like this way.