$ location.path不起作用 [英] $location.path is not working

查看:71
本文介绍了$ location.path不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户输入正确的用户名和密码后,我想重定向到另一个位置.但是当我在这里使用$location.path('dashboard')时,浏览器的URL被更改,但该页面未加载.当使用ctrl + R刷新我的页面或单击浏览器的刷新图标时,将加载适当的页面.

When user has enter correct username and password I want redirect to another location. But when I used $location.path('dashboard') here then URL of browser is changed but that page not loaded.when refresh I page using ctrl+R or click on refresh icon of browser then appropriate page is loaded.

$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;

        });
    };

}]);

推荐答案

您是否尝试过使用$ scope.$ apply?例如:

if(!$scope.$$phase) $scope.$apply()

这种简短的方法也经常派上用场:

https://github.com/yearofmoo/AngularJS-Scope.SafeApply

这篇关于$ location.path不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆