Custom Attribute Directive with AngularJS


Custom Attribute Directive with AngularJS



In my html i have added directive as below


<html ng-app="xxxxx" bm-app="auth">



Directive:


angular.module('xxxxx').directive('bmApp', bmApp);

bmApp.$inject = ['$document', '$log', 'matchmedia', 'AuthenticatedSession', 'bmUser'];

function bmApp($document, $log, matchmedia, authenticatedSession, bmUser) {

return {
restrict: 'EA',
controller: [function () { }],
scope: true,
link: function (scope, element, attrs) {
var html = $document.find('html');

if (attrs.bmApp !== 'pre-auth') {
/* load intrinsic post-auth objects */
authenticatedSession.load().then(function(data) {
$log.log('session:', { meta: data.meta, bindings: data.bindings });
}).finally(function () {
html.addClass('bm-resolved');
});
bmUser.load();
}
}
};
}



I just want to validate whether the user is authenticated or not. If not i need to redirect user to login page using custom directive. I am new to AngularJs, please someone help me to sort this out.





What is your question?
– jbrown
Jul 2 at 13:59





@jbrown My question is how to redirect user to login page if not authenticated?
– Shivanand koli
Jul 2 at 14:14





There a several posts on this site that address different ways of handling this scenarion. Search 'angularjs redirect to login'
– jbrown
Jul 2 at 14:18









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages