How to get the current route in the resolution function?

I have a service that checks if the current user has access to a route. I would like this service to be called as part of the permission so that the view never loads if the user should not have access. However, in the resolution function, the $ state dependency does not yet contain the actual state of the router.

.state('home', {
  url: '/home',
  templateUrl: 'app/home.html',
  controller: 'HomeController',
  controllerAs: 'main',
  resolve: {
    allowed: function(auth, $state) {
      return auth.isAllowed($state.current.name);
    }
  },
})

... however $state.current.nameempty at the point at which it is used. How to pass the name of the state (ie "Home")?

+4
source share
2 answers

Try

resolve: {
   allowed: function(auth) {
      return auth.isAllowed(this.self.name);
   }
},
+4
source

UI- 1.0+: $state $, ( ). , , , , .

resolve: {
    allowed: function($state$) {
    ...
    }
}
0

Source: https://habr.com/ru/post/1667036/


All Articles