2
我已经添加了这个模块我的应用程序:https://github.com/witoldsz/angular-http-auth/blob/gh-pages/lib/http-auth-interceptor.js
这对401级的响应广播消息,非常方便!只是不知道如何让我的$ routeProvider监听$ rootscope。$ broadcast。我想重定向到401s上的登录页面。
我的$ routeProvide看起来是这样的:
var app = angular.module('demoApp', ['http-auth-interceptor','tastypieModule'])
.config(function($routeProvider) { $routeProvider.
when('/', {controller:HomeCrtl, templateUrl:'partials/home.html'}).
when('/sign-in', {controller:SiginInCtrl, templateUrl:'partials/sign-in.html'}).
otherwise({redirectTo:'/'});
})
我的$ routeProvider将有很多控制器。我正在寻找一种倾听401s的全球方式。 –
我会更新我的答案,以便更具体。 –
Brill的作品(更有意义,但有此事件:“event:auth-loginRequired”)谢谢:) –