IonicModal:$ scope.ionicModal.show()在调用$ scope.ionicModal.remove()后无效

时间:2015-10-28 18:33:46

标签: angularjs ionic

我创造了一种离子模态。当我第一次点击这个

<label class="list card">
<textarea ng-click="newPost(1); content = '' " placeholder="Write here"></textarea></label>

这是新的帖子功能

// Open our new task modal
  $scope.newPost = function(index) {
       if (index == 1){
        $scope.postModal.show()
       }else {$scope.selectModal.show();}
     // $scope.postModal.show();

  };
        </label>

它弹出离子模态,然后在其他隐藏和破坏离子模态,我点击这个

<button style="border: 3px solid red; border-radius:5px; color: #ff6000" class="button button-clear button-positive" ng-click="closeNewPost(1);content= '' ">Clear</button>

这是隐藏和删除功能

// Close the new task modal
  $scope.closeNewPost = function(index) {
       if (index == 1) {
    $scope.postModal.hide();
      $scope.postModal.remove();
      } else {
          $scope.selectModal.hide();
       }
      //$scope.postModal.hide();
      // $scope.postModal.hide();
  };

现在,我的挑战是第二次点击它,它再也不会弹出离子模态

<label class="list card">
<textarea ng-click="newPost(1); content = '' " placeholder="Write here"></textarea></label>

您可以查看离子模态文档

http://learn.ionicframework.com/formulas/making-modals/

请问有什么不对。

1 个答案:

答案 0 :(得分:2)

由于您正在删除模式,因此无法再次显示。 docs on ionicmodal解释在模式上运行remove()将:

  

从DOM中删除此模态实例并进行清理。

如果您只想隐藏/显示相同的模式,请使用hideshow。如果要从dom中删除模态,请使用remove,但请确保在想要再次显示模式时重新创建模态。

Making modals显示了如何创建模态:

$ionicModal.fromTemplateUrl('contact-modal.html', {
  scope: $scope,
  animation: 'slide-in-up'
}).then(function(modal) {
   $scope.modal = modal
})  

如果您想从ng-click调用此代码,只需将其放在方法中并将其附加到您控制器的范围内:

$scope.createModal = function() {
    $ionicModal.fromTemplateUrl('contact-modal.html', {
      scope: $scope,
      animation: 'slide-in-up'
    }).then(function(modal) {
       $scope.modal = modal
    })  
}