【问题标题】:Ionicmodal Doesn't Open Until Third Click/TapIonicmodal 直到第三次单击/点击才会打开
【发布时间】:2016-01-03 17:47:19
【问题描述】:

我已将divon-tap 值设置为打开页面控制器中定义的模式。 divng-repeat 部分的一部分。 modal 函数还接受div 传递给它的一些变量。

当应用程序在我的设备(运行 iOS 7 的 iPhone 6)上首次启动时,我必须点击 div 三次才能打开模式。之后,当我点击时它会持续打开。但是当应用第一次启动时,我必须点击 div 3 次。

控制台中完全没有错误。一旦模式打开,它就会按预期工作。

有什么建议吗?

代码如下:

HTML

  <div on-tap="doModal('{{embed.ID}}','reply','{{embed.oembed}}','{{embed.user}}');">
     <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75 72" width="100" height="50">
      <path d="imagestuffhere"/>
      </svg>
   </div>

控制器

$scope.doModal = function(this_ID,modaltype,this_oembed,this_user) {    
  $scope.contact = {
    name:   this_ID,
    info:   modaltype,
    oembed: this_oembed,
    user:   this_user
  }

  if (modaltype == 'repost') {
    $scope.modaltempl = 'templates/repost-modal.html';
  }
  else if (modaltype == 'reply') {
    $scope.modaltempl = 'templates/reply-modal.html';
  }
  else if (modaltype == 'like') {
    $scope.modaltempl = 'templates/like-modal.html';
  }
  else {
    $scope.modaltempl = 'templates/like-modal.html';
  }

  $ionicModal.fromTemplateUrl($scope.modaltempl, {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function (modal) {
    $scope.modal = modal;
    $scope.modal.show();
    console.log($scope.modaltempl);
  });
};    

  $scope.closeModal = function() {
    $scope.modal.hide();
  };

  $scope.$on('$destroy', function() {
    $scope.modal.remove();
  });

我尝试将$ionicModal.fromTemplateUrl($scope.modaltempl, 位拉到$scope.doModal 之外并从$scope.doModal 内部调用$scope.modal.show,但结果是一样的。

即使模式没有打开,它也肯定会到达scope.modal.show(); 语句,因为console.log 在它得到输出后我已经包含了。

在我将 svg 添加到界面之前,我使用 button 元素对此进行了测试,并且遇到了同样的问题。当我使用ng-click 而不是on-tap 时,它也有同样的问题。

感谢您的帮助!

【问题讨论】:

    标签: ionic-framework ionic


    【解决方案1】:

    原来问题不在于 Ionic 控制器代码或触发 html,而在于模态模板本身。

    根据 Ionic 文档,我的每个模态模板都包含在以下内容中:

    &lt;script type="text/ng-template" id="repost-modal.html"&gt;&lt;/script&gt;

    通过将其删除并仅将其替换为 &lt;ion-modal-view&gt;&lt;/ion-modal-view&gt;,问题已得到解决,并且模态现在在第一次单击时打开得非常好。

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 2013-05-23
      • 1970-01-01
      • 2017-07-03
      • 2011-10-23
      • 1970-01-01
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多