【发布时间】:2014-05-21 00:52:26
【问题描述】:
全部,
我正在开发一个 AngularJS PhoneGap 应用程序。我被困在收到 API 调用响应后立即发生的一个重定向。我的代码位于gist.github.com
我的问题在 controllers.js 的第 300 行,我在 then() 块中调用我的重定向。
UserService.login($scope.user.email, $scope.user.password)
.then(function(response) {
globals.session_id = response.data.meta.session_id;
globals.logged_in_userId = response.data.response.users[0].id;
if ($scope.user.remember === true) {
window.localStorage.setItem("_session_id", response.data.meta.session_id);
window.localStorage.setItem("logged_in_userId", response.data.response.users[0].id);
} else {
window.localStorage.removeItem("_session_id");
window.localStorage.removeItem("logged_in_userId");
}
})
.then(function() {
$location.path("/tab/locations");// <=== This line doesn't cause an error but does not result in a redirect
})
.
catch (function(response) {
alert(JSON.stringify(response));
});
如果有人可以帮助我,我将不胜感激!
谢谢, 布鲁斯
【问题讨论】:
-
到目前为止,我已经尝试过使用 rootScope apply、scope apply,并在 promise return 中使用变量以及 scope watch,但重定向始终不起作用。我也尝试过使用 window.navigation.href,但我仍然一无所获。成功登录后必须有一种方法来重定向用户。
标签: javascript angularjs cordova location