【发布时间】:2013-08-11 04:17:52
【问题描述】:
当用户输入正确的用户名和密码时,我想重定向到另一个位置。但是当我在这里使用$location.path('dashboard') 时,浏览器的 URL 已更改,但该页面未加载。当使用 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;
});
};
}]);
【问题讨论】:
-
在那之后你有没有尝试过使用 $scope.$apply ?例如。
if(!$scope.$$phase) $scope.$apply() -
@RafalPastuszak 你的回答对我有用。请把它作为一个单独的答案提出来
-
@davneet 完成,谢谢。
标签: angularjs