登录测试后,我尝试转到主页,但是我遇到了问题。我用$ location.path(“ / templates / welcome.html”);
但它不起作用。

我在app.js中的控制器是:

controller('SignInCtrl', function($scope, $state, $http) {

    $scope.login = function(user) {
        $http.get("http://localhost/app_dev.php/json/login/"+user.username+"/"+user.password)
        .then(function(response){
            console.log(response.data.status);
            if(response.data.status === 200)
            {
                alert("redirect to main page");
                $location.path("/templates/welcome.html");
            }else if(response.data.status === 403){
                alert("Login or password incorrect");
            }else{
                alert("User not found");
            }
        });
    };
})


警报有效,但重定向无效。在控制台中,我有此错误:

ionic.bundle.js:25642 ReferenceError: $location is not defined
    at app.js:37

最佳答案

像这样将$ location注入控制器

controller('SignInCtrl', function($scope, $state, $http, $location) {

09-17 17:30
查看更多