如何在解析函数中获取当前路由?

geo*_*sic 7 angularjs angular-ui-router

我有一个服务,检查当前用户是否有权访问该路由.我希望将该服务作为解析的一部分进行调用,以便在用户不具有访问权限时从不加载视图.但是,在resolve函数中,$ state依赖项尚未包含路由器的实际状态.

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

......但是$state.current.name在使用它时是空的.我怎样才能传递州名(即"家")?

Dar*_*rio 5

试试吧

resolve: {
   allowed: function(auth) {
      return auth.isAllowed(this.self.name);
   }
},
Run Code Online (Sandbox Code Playgroud)