【问题标题】:AngularJS $location not working in logout functionAngularJS $location 在注销功能中不起作用
【发布时间】:2016-11-18 14:42:10
【问题描述】:

已阅读此主题 Angular not changing the pathAngular location path not working 但仍然不明白为什么会发生这种情况。

这是我在控制器中的功能。

$scope.logout = function () {

sessionService.destroy('isLoggedIn');   
sessionService.destroy('role'); 
sessionService.destroy('sessionToken');

if(sessionService.get('sessionToken') != null){
//$scope.isLoggedIn = true; 
$scope.hasNotsignedIn = false;  
}else {
$scope.hasNotsignedIn = true;   
//$scope.isLoggedIn = false;
}

$location.path("/"); //this not working 

}

$location 已经注入控制器并且路由已经定义。我在其他功能中还有其他 $location.path 可以正常工作。

那么我的代码有什么遗漏或错误吗?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    如果路径相同$location.path("/");将不起作用。

    你必须使用$route.reload();

    【讨论】:

    • 只是尝试$location.path("/otherPath");$route.reload();正如你所说但仍然无法正常工作。
    猜你喜欢
    • 1970-01-01
    • 2012-06-25
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2016-08-25
    • 2020-06-11
    相关资源
    最近更新 更多