Javascript AngularJS$location.path(url)未重定向

Javascript AngularJS$location.path(url)未重定向,javascript,angularjs,cordova,location,Javascript,Angularjs,Cordova,Location,全部, 我有一个AngularJS PhoneGap应用程序正在开发中。我被一个重定向卡住了,这个重定向在收到API调用响应后立即发生。我的代码位于 我的问题是controllers.js的第300行,在那里我在then()块中调用我的重定向 UserService.login($scope.user.email,$scope.user.password) .然后(功能(响应){ globals.session\u id=response.data.meta.session\u id; glob

全部,

我有一个AngularJS PhoneGap应用程序正在开发中。我被一个重定向卡住了,这个重定向在收到API调用响应后立即发生。我的代码位于

我的问题是controllers.js的第300行,在那里我在then()块中调用我的重定向

UserService.login($scope.user.email,$scope.user.password)
.然后(功能(响应){
globals.session\u id=response.data.meta.session\u id;
globals.logged\u in\u userId=response.data.response.users[0].id;
if($scope.user.memory===true){
setItem(“\u session\u id”,response.data.meta.session\u id);
window.localStorage.setItem(“登录用户id”,response.data.response.users[0].id);
}否则{
window.localStorage.removietem(“\u session\u id”);
window.localStorage.removietem(“登录用户ID”);
}
})
.然后(函数(){

$location.path(“/tab/locations”);//您的
然后
处理程序需要返回一些内容,以便在下一个条件下仍然解析承诺

只需在
的末尾添加
返回响应
,然后添加
处理程序。

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


您还可以使用$location.url()

问题似乎实际上出现在我的app.js run函数调用中。在位置更改时,它会查看全局变量以查看是否已设置用户名,如果未设置,则会截取调用以将客户端发送到登录页面。一旦我将代码移到OnLocationChange处理程序中查看该变量,它就会正确重定向

谢谢,
B

Hi Alp,谢谢你的回复。我刚刚尝试过,但仍然没有重定向。如果使用
window.location.href=“/tab/locations”,是否有效
?您好,阿披舍克,谢谢您的回复。不幸的是,我尝试了两种方法,但都没有成功。对我有效。谢谢!到目前为止,我已经尝试了使用rootScope应用、scope应用,以及在promise return和scope watch中使用一个变量,但重定向在任何时候都不起作用。我还尝试了使用window.navigation.href,我仍然得到了支持没有。必须有一种方法在成功登录后重定向用户。
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));
        });
$scope.$apply(function() {
  $location.path("/tab/locations");
});