search

Home  >  Q&A  >  body text

angular.js - angularjs 公用的方法

问题是这样:

    在项目所有的路由页面需要请求后台的一个唯一ID值,然后与前端存储在session的值作比较,不相同则跳转到指定页面,相同则不作处理。
    需要在每个路由页面提取session的值来比较,这个是应该直接写一个service然后注入到controller还是需要其他方法来做?
    
我想大声告诉你我想大声告诉你2744 days ago586

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味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,

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 17:14:37

    You can also do verification processing in the parent controller

    reply
    0
  • Cancelreply