3

/auth/logoutセッションが削除された後、URLを呼び出してリダイレクトしようとしています:

app.config(['$routeProvider',function($routeProvider) {
    $routeProvider
    .when('/auth/logout',{
        controller:'AuthLogout'
        //templateUrl: not needed

    })
})
.controller('AuthLogout', ['$window','$location', function ($window,$location) {
    $window.localStorage.removeItem('user_username');
    $window.localStorage.removeItem('user_id');
    $window.localStorage.removeItem('user_session_token');
    $location.path('/');
}]);

実際には AuthLogout コントローラーのビューは必要ありませんが、templateUrlrouteProvider で指定しないと機能しませんが、指定するtemplateUrlと機能します。

ビューをロードせずに url/controller を呼び出すにはどうすればよいですか??

4

3 に答える 3

5

投稿に従って解決ハンドラーを使用できますhttps://github.com/angular/angular.js/issues/1838

この簡単な例を確認して、解決のアラート ステートメントに注目してください。

http://jsfiddle.net/Wk7WD/34/

.when('/detail/:id/', {
    resolve: {
        load: function ($route, dataService) {
            alert("hello");
            //Your statements instead of all this which I found in an example
            return dataService.load($route.current.params.id);
        }
    }
})

アラートの代わりに、独自のステートメントを持つことができます

于 2014-02-18T13:01:00.297 に答える