I want to create an angularjs directive for restricted actions of my web site. For example I have an anchor which would trigger a route change in angular, but before that I want to show a modal login dialog.
I can stop the routing with preventDefault
, but I can't resume the routing. I have also tried with dummy event triggering (element.triggerHandler('click')
) without success.
I'd like to apply the directive not only to route changing but any other action.
.directive('loginRequired', ['AuthService', 'AUTH_EVENTS',
function(AuthService, AUTH_EVENTS) {
return {
link : function(scope, element, attrs) {
element.on('click', function(e) {
if (!AuthService.isAuthenticated()) {
e.preventDefault();
$('#myModal').modal();
scope.$on(AUTH_EVENTS.loginSuccess, function() {
//resume event
});
console.log('$scope.$on happened');
}
});
}
}
}]);
Any suggestion?