离子模态打开了以前的模态

时间:2016-05-20 07:24:21

标签: javascript jquery ionic-framework ionic2

大家好我正试图打开一个模态。事情是我已经用模板将我的模态结合起来,现在我试图将另一个模态与$ ionicmodal绑定,但它打开了前一个模态。有人可以告诉我,我做错了什么

首先将模态绑定在APPCtrl

.controller('optionActionCtrl' , function($scope, $timeout , $http , $ionicModal){



  $scope.closeActionModal = function() {
    console.log('hello');
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.openAddActionModel = function() {
    $scope.modal.show();
    // $('#action_datePicker').val(new Date());
  };

  $scope.showListOfUser = function(){
    //call made to the server
    //bind the modal to get it open
     $ionicModal.fromTemplateUrl('templates/showUsers.html', {
      scope: $scope
    }).then(function(modal) {
      debugger;
      $scope.modal = modal;
    });
    $scope.modal.show();
    // add all the users 
    $scope.users = ['a' , 'b' , 'c' , 'd'];
  };
})

现在我想在show List用户中绑定模态,但它显示的是前一个

<ion-view view-title="ShowUserList">
  <ion-content>
    <!-- <ion-checkbox ng-model='checkStatus1' ng-click="showAlert(checkStatus1)">
        <h2 class="ng-binding">{{tittle}}</h2>
        <span class="distance ng-binding"></span>
        <h3 class="ng-binding">Created : {{created}}</h3>
        <h3 class="ng-binding">Target : {{targetD}}</h3>
    </ion-checkbox>  -->

    <ion-list>
      <ion-item  collection-repeat="user in users">
        Hello, {{user}}!
      </ion-item>
    </ion-list>


  </ion-content>

请告诉我,我做错了什么

更新

现在我试图打开状态并查看一些数据但问题是我无法看到用户而不是所有HTML正在呈现。以下是我的观点代码:

.controller('optionActionCtrl' , function($scope, $timeout , $http , $ionicModal , $state){
    // Triggered in the login modal to close it

    $scope.users = [];

  $scope.closeActionModal = function() {
    console.log('hello');
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.openAddActionModel = function() {
    $scope.modal.show();
    // $('#action_datePicker').val(new Date());
  };

  $scope.showListOfUser = function(){
    debugger;
    // add all the users 
    $scope.users = ['a' , 'b' , 'c' , 'd'];

    $state.go('app.UserListForAssigned')
  };
})

我已经稍微改变了控制器

{{1}}

1 个答案:

答案 0 :(得分:2)

修复您的optionActionCtrl控制器。将$scope.modal.show()置于回调中。

.controller('optionActionCtrl' , function($scope, $timeout , $http , $ionicModal){
    $scope.closeActionModal = function() {
        console.log('hello');
        $scope.modal.hide();
    };

    $scope.openAddActionModel = function() {
        $scope.modal.show();
    };

    $scope.showListOfUser = function () {
        $ionicModal.fromTemplateUrl('templates/showUsers.html', {
            scope: $scope
        }).then(function(modal) {
            $scope.modal = modal;
            $scope.modal.show(); // Moved inside the callback
            $scope.users = ['a' , 'b' , 'c' , 'd']; // I assume this is relevant to your modal
        });
    };
})