登录完成后无法正确重定向

时间:2015-04-21 11:25:59

标签: routing ionic

我正在尝试像以下示例中那样执行登录页面: https://github.com/keithdmoore/ionic-http-auth 我有两个问题:

1.尝试重新修改到应用页面时出现错误

Error: Cannot transition to abstract state 'app'

代码:

  .controller('LoginCtrl', function ($scope, $state, AuthenticationService) {
    $scope.message = "";

    $scope.user = {
        username: null,
        password: null
    };

    $scope.login = function () {
        AuthenticationService.login($scope.user);
    };

    $scope.$on('event:auth-loginRequired', function (e, rejection) {
        console.log('handling login required');
        $scope.loginModal.show();
    });

    $scope.$on('event:auth-loginConfirmed', function () {
        $scope.username = null;
        $scope.password = null;
      $state.go('app');
    });

应用程式:

       .state('app', {
        url: "/app",
        abstract: true,
        templateUrl: "templates/menu.html",
        controller: 'AppCtrl'
    })
    .state('app.placeslists', {
        url: "/placeslists",
        cache: false,
        views: {
            'menuContent': {
                templateUrl: "templates/placeslists.html",
                controller: 'PlaceslistsCtrl'
            }
        }
    })

2.第二个问题看起来像gui的一些问题,我试图采用登录模板的列表示例,但它看起来不像离子组件的例子。 我的模板

<ion-view>
  <ion-content>
<div class="list"  ng-controller="LoginCtrl">
    <label class="item item-input">
        <input type="text" placeholder="Username" ng-model="user.username" required>
    </label>
    <label class="item item-input">
        <input type="password" placeholder="Password" ng-model="user.password" required>
    </label>
</div>
</ion-content> 
</ion-view>

2 个答案:

答案 0 :(得分:0)

关于问题1,我在github上看到以下$scope.loginModal.hide(); 代替您的代码:$state.go('app');

关于问题2,您应该查看ionic components<ion-nav-view> , <ion-content> , <ion-list> , <ion-item>

答案 1 :(得分:0)

只需导航到主页或其他内容,即:

.state('app.home', {
        url: "/home",
        cache: false,
        views: {
            'menuContent': {
                templateUrl: "templates/home.html"
            }
        }
    })

$scope.$on('event:auth-loginConfirmed', function () {
        $scope.username = null;
        $scope.password = null;
        $state.go('app.home');
    });