首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >$location.path不工作

$location.path不工作
EN

Stack Overflow用户
提问于 2013-08-09 16:52:18
回答 3查看 30.5K关注 0票数 18

当用户输入正确的用户名和密码时,我希望重定向到另一个位置。但是当我在这里使用$location.path('dashboard')时,浏览器的URL会改变,但该页面不是loaded.when,而是使用ctrl+R刷新页面,或者单击浏览器的刷新图标,然后加载相应的页面。

$http.post('/login', $scope.userInfo)
        .success(function (data) {
            //Check if the authentication was a success or a failure
            //Successful POST here does not indicate success of authentication
            if (data.status === "authentication success") {

                //Proceed to load the dashboard for the user                    
                $location.path('/dashboard');

            } else if (data.status === "authentication error") {
                //Inform user of the error
                $scope.errorMessage = data.error;
                $scope.showErrorMessage = true;
            }

        })
        .error(function (error) {
            $scope.errorMessage = "Error while attempting to authenticate. Check  log.";
            $scope.showErrorMessage = true;

        });
    };

}]);
EN

回答 3

Stack Overflow用户

发布于 2016-03-21 20:06:09

试试这个(别忘了注入$timeout):

$timeout(function () {
   $location.path('/dashboard'); 
}, 0);
票数 3
EN

Stack Overflow用户

发布于 2017-11-07 06:41:12

使用$timeout(function){}这将起作用

票数 0
EN

Stack Overflow用户

发布于 2014-04-23 21:35:29

尝试:

 $location.path('/dashboard');
 $location.reload();
票数 -6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18143189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档