I'm looking to develop a directive that hides specific elements for guest users. Here is the current code I have:
angular.module('someMod')
.directive('premiumUser', premiumUser)
.controller('PremiumUserCtrl', PremiumUserCtrl);
function premiumUser () {
return {
restrict : 'A',
link : premiumUserLink,
controller : 'PremiumUserCtrl',
};
}
function premiumUserLink (scope, element) {
if (!scope.checkLoggedIn())
element.hide();
}
function PremiumUserCtrl ($scope, sessionManager) {
$scope.checkLoggedIn = function () {
return sessionManager.isUserLoggedIn();
};
}
When I use this directive on an element like so:
<ANY premium-user></ANY>
it works, but the targeted directive's controller still initializes and executes onInit code.
Is there a way to modify this directive to prevent controller initialization?
Thank you in advance!