admin管理员组文章数量:1290228
I'm trying calling the /auth/logout
url to get redirected after session is deleted:
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('/');
}]);
I actually don't need a view for AuthLogout controller but if I do not specify the templateUrl
in routeProvider I can't get this to work, while if I specify a templateUrl
it works.
How can I call the url/controller without to having to load a view??
I'm trying calling the /auth/logout
url to get redirected after session is deleted:
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('/');
}]);
I actually don't need a view for AuthLogout controller but if I do not specify the templateUrl
in routeProvider I can't get this to work, while if I specify a templateUrl
it works.
How can I call the url/controller without to having to load a view??
Share Improve this question edited Feb 18, 2014 at 19:15 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked Feb 18, 2014 at 11:32 Filippo orettiFilippo oretti 49.9k96 gold badges229 silver badges351 bronze badges 3- Try template:'' a little tricky but it should work ^^ – Whisher Commented Feb 18, 2014 at 11:40
- i get a an infinite loop and the browser crashes with this :O – Filippo oretti Commented Feb 18, 2014 at 11:47
- this is strange in the when block you can use or template or templateUrl so the infinite loop I think it's not relate. – Whisher Commented Feb 18, 2014 at 11:53
3 Answers
Reset to default 6You could do :
.when('/auth/logout', {
controller: function(){
//do staff
}
})
btw may be there is something wrong in your code because template works and you could exploit it in the same way
http://docs.angularjs/api/ngRoute/provider/$routeProvider
You can use a resolve handler according to the post https://github./angular/angular.js/issues/1838
Checkout this quick example and notice the alert statement in resolve.
http://jsfiddle/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);
}
}
})
Instead of the alert you can have your own statements
use redirectTo
app.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when('/auth/logout',{
redirectTo:'/'
})
});
Hope this will work for you :)
本文标签: javascriptAngular jscall a route without viewStack Overflow
版权声明:本文标题:javascript - Angular js - call a route without view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741460079a2379985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论