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」)謝謝:) –