AngularJS $ location.path(url)不重定向

jax*_*ier 2 javascript location angularjs cordova

所有,

我有一个我正在研究的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));
        });
Run Code Online (Sandbox Code Playgroud)

如果有人能帮助我,我会很感激!

谢谢,布鲁斯

Abh*_*hek 7

试试$ rootScope.$ apply(); 在$ location.path()之后

要么

$scope.$apply(function() {
  $location.path("/tab/locations");
});
Run Code Online (Sandbox Code Playgroud)

你也可以使用$ location.url()