The question is this:
在项目所有的路由页面需要请求后台的一个唯一ID值,然后与前端存储在session的值作比较,不相同则跳转到指定页面,相同则不作处理。 需要在每个路由页面提取session的值来比较,这个是应该直接写一个service然后注入到controller还是需要其他方法来做?
It is possible to write a service and inject it into the controller.
But my method is to do it in angular.module.run
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,
$httpProvider.interceptors.push('authInterceptor')
You can also do verification processing in the parent controller
It is possible to write a service and inject it into the controller.
But my method is to do it in angular.module.run
The author can determine the routing in the root controller and then set the sub-rules:
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,You can also do verification processing in the parent controller