离子重定向

Ionic redirection

本文关键字:重定向      更新时间:2023-09-26

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

我在应用程序中的控制器.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) {

您尚未在控制器中注入$location服务。

我认为问题来自statProrovider。我的状态是:

.config(function($stateProvider, $urlRouterProvider) {

    $stateProvider
        .state('signin', {
            url: '/sign-in',
            templateUrl: 'templates/welcome.html',
            controller: 'SignInCtrl'
        })
})

在我的网页中:

<div ng-controller="SignInCtrl">
<form novalidate class="simple-form">
  <div class="list list-inset">
      <label class="item item-input">
          <input type="text" placeholder="Username" ng-model="user.username">
      </label>
      <label class="item item-input">
          <input type="password" placeholder="Password" ng-model="user.password">
      </label>
  </div>
  <button class="button button-block button-calm" ng-click="login(user)">Login</button>
</form>

我刚刚开始使用Ionic,这就是为什么