Try the following
$scope.$on('$routeChangeStart'
There is also a good tutorial
here:
http://nadeemkhedr.wordpress.com/2013/11/25/how-to-do-authorization-and-role-based-permissions-in-angularjs/
Regards,
Garry Taylor
On Friday, 16 May 2014 14:57:47 UTC+1, Marc B wrote:
>
> Hello,
> In my ui-router I added for each state a data property specifying an
> access level - either 'anon' or 'user': a state with a value 'anon' should
> be acessible for any user, a ste with an acess level of 'user' should be
> accessible for logged-in users. Example:
>
>
> .config(['$urlRouterProvider','$stateProvider',function($urlRouterProvider,$stateProvider){
> $urlRouterProvider.otherwise('/home');
>
> // Anonymous route
> $stateProvider
> .state('login',{
> url:'/login',
> templateUrl:"app/views/login.html",
> controller:"SecurityController",
> data:{
> access: 'anon'
> }
> })
> //secured route
> .state('home',{
> url:'/home',
> templateUrl:"app/views/home.htm",
> controller:"SecurityController",
> data:{
> access: 'user'
> }
> })
>
> I check the state of the view user wants to load at $readyStateChange
> event:
>
> $rootScope.$on('$stateChangeStart',
> function(event,toState,toParams,fromState,fromParams){
> // check toState.data.access to current user access level
>
> This works fine. When I'm not logged in and a page with accesslevel 'anon'
> is loaded and I try to load a page with access level 'user' I am redirected
> to the login page. But when I'm not logged in and navigate directly to one
> of the pages with accesslevel 'user', the requested page is loaded and
> there is no redirect. It looks like the $stateChangeStart event is never
> fired in this case because any console.log() in the body of the callback
> function does not display.
>
> How can I restrict acess to a pages also in this case?
>
> Thanks,
>
> Marc
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.