当用户输入正确的用户名和密码时,我希望重定向到另一个位置。但是当我在这里使用$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;
});
};
}]);
发布于 2016-03-21 20:06:09
试试这个(别忘了注入$timeout):
$timeout(function () {
$location.path('/dashboard');
}, 0);
发布于 2017-11-07 06:41:12
使用$timeout(function){}这将起作用
发布于 2014-04-23 21:35:29
尝试:
$location.path('/dashboard');
$location.reload();
https://stackoverflow.com/questions/18143189
复制相似问题