问题是这样:
在项目所有的路由页面需要请求后台的一个唯一ID值,然后与前端存储在session的值作比较,不相同则跳转到指定页面,相同则不作处理。
需要在每个路由页面提取session的值来比较,这个是应该直接写一个service然后注入到controller还是需要其他方法来做?
漂亮男人2017-05-15 17:14:37
It is possible to write a service and inject it into the controller.
But my method is to do it in angular.module.run
淡淡烟草味2017-05-15 17:14:37
The author can determine the routing in the root controller and then set the sub-rules:
$rootScope.$on('$stateChangeSuccess', function(){//Todo sth});
If the poster doesn’t like this method, you can also inject $httpProvider into the config and add $httpProvider.interceptors.push('authInterceptor')
and an authInterceptor service,