我有一个打开第二个模式,不能关闭第一模如果打开然后关闭第二模态 [英] I have a modal that opens a second modal and cannot close the first modal if open then close the second

查看:137
本文介绍了我有一个打开第二个模式,不能关闭第一模如果打开然后关闭第二模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要开始我创建了一个 codePEN ,我认为冠军说明了一切。我创建了一个服务来处理我的情态动词,因为在这里看到

To start I created a codepen and I think the title says it all. I created a service to handle my modals, as seen here

.service('ModalService', function($ionicModal, $ionicLoading, $rootScope) {
    var init = function(tpl, $scope) {
      $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
      });

      var promise;
      $scope = $scope || $rootScope.$new();
      promise = $ionicModal.fromTemplateUrl(tpl, {
        scope: $scope,
        animation: 'slide-in-up'
      }).then(function(modal) {
        $scope.modal = modal;
        return modal;
      });
      $scope.$on('$destroy', function() {
        $scope.modal.remove();
      });
      return promise;
    }
    return {
      init: init
    }
  })

和它被调用在控制器中像这样

and it gets called in the controller like so

   ModalService.init('modal.html', $scope).then(function(modal) {
        ...do something....
        $ionicLoading.hide();
        modal.show();
      });

这是我只能关闭一个模式,第一个或第二,但如果我进入第二个我不能关闭第二个问题吧。林假设当我关闭一个它摧毁两个模态实例?我怎样才能解决这个,如果我不想把它切成不同的控制器?

The issue it that I can only close one modal, the first one or the second, but if I go into the second I cannot close the second. Im assuming when I close one its destroying the modal instance for both? How can I work around this if I do not want to slit it into different controllers?

推荐答案

您指定的模式控制器通过 $ ionicModal.fromTemplateUrl返回的所有实例(...),然后(模式)函数$ scope.modal。

You assigned all the instances of modal controller returned by $ionicModal.fromTemplateUrl(...).then(modal) function to $scope.modal.

第二个实例覆盖的第一个,所以当您关闭第二个,然后尝试使用隐藏的关闭按钮,第一个( NG-点击=modal.hide() $ scope.modal 仍然指向到2 ...

The second instance "overwrites" the first one, so when you close the 2nd and then try to hide the first one using the close button (ng-click="modal.hide()") $scope.modal still points to the 2nd...

所以,在你的服务,你必须单独存储模式控制器$ ionicModal的每个实例。
这里是一个可能的编辑到code:

So, in your Service you have to store modal controller individually for each instance of $ionicModal. Here is a possible edit to your code:

的http://$c$cpen.io/beaver71/pen/dGKBmv

还要检查这个帖子:<一href=\"http://stackoverflow.com/questions/29969588/how-to-create-two-ionic-modal-in-a-cordova-app\">How要在科尔多瓦的应用程序创建两个离子态?
或者这一个:离子多情态动词只持续显示

这篇关于我有一个打开第二个模式,不能关闭第一模如果打开然后关闭第二模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆