【问题标题】:ionic popup close not working离子弹出关闭不起作用
【发布时间】:2017-01-16 16:47:13
【问题描述】:

我创建了一个 ionic 应用程序,在该应用程序中会打开一个弹出窗口,让用户在之前未评价此应用程序的情况下要求用户评价此应用程序。离子弹出窗口正确显示,但我的问题是,用户必须点击/点击取消按钮两次才能关闭弹出窗口,有时点击/点击不起作用。

我的代码如下:

 (function() {

      $scope.data = {}

      var myPopup = $ionicPopup.show({
        template: '<input type="range" ng-model="data.user_ratting">',
        title: 'Do you want to rate this app?',
        scope: $scope,
        buttons: [
          { text: 'Cancel' },
          {
            text: '<b>Save</b>',
            type: 'button-positive',
            onTap: function(e) {

             }
          }
       ]
  });

    myPopup.then(function(res) {
      console.log('Tapped!', res);
    });

 })();

我该如何解决这个问题??

【问题讨论】:

  • 您在哪里测试您的应用程序?您使用的是哪个版本的框架?
  • 我在安卓模拟器上测试我的应用,离子版本是 1.6.4
  • 这个 $scope 变量从何而来?它是否打算成为一个干净的 $scope (因此包含 function() ?)

标签: angularjs ionic-framework


【解决方案1】:

你能试试这个吗

var popup = $ionicPopup.show({
    title: 'Enter Wi-Fi Password',
    subTitle: 'Please use normal things',
    scope: $scope,
    buttons: [
              { text: 'ready',  onTap: function(e) {
                  console.log(e);
                  return true; 
                } 
           }
             ]
  }).then(function(result){
    console.log('Tapped', result);
  }, function(error){
    console.log('error', error);
  }, function(popup){
    popup.close();
  })

【讨论】:

  • 感谢您的回答,但是当我尝试在 switch case 中显示弹出窗口时,它不起作用确实知道任何解决方案
  • case 'false': $ionicPopup.show({ title: 'Invalid Passcode!', template: '请输入有效密码。', scope: $scope, buttons: [ { text: 'Ok', 输入: 'button-positive', onTap: function(e) { } } ] });对于开关盒它不起作用
【解决方案2】:

请看看我为你做的代码笔:

http://codepen.io/privetr/pen/QjjyMB

$scope.openPopup = function() {
  var myPopup = $ionicPopup.show({
    template: '<input type="range" ng-model="data.user_ratting">',
    title: 'Do you want to rate this app?',
    scope: $scope,
    buttons: [
      { text: 'Cancel' },
      {
        text: '<b>Save</b>',
        type: 'button-positive',
        onTap: function(e) {

         }
      }
   ]
});

myPopup.then(function(res) {
  console.log('Tapped!', res);
});
}

// To automatically open the popup
$scope.openPopup();

此代码有效,我只是添加了一个函数,用于在单击右上角按钮时调用 Popup。

希望能解决你的问题!

【讨论】:

  • 点击事件有效,但我需要自动加载弹出窗口
  • 然后,函数初始化完成后,调用$scope.openPopup();我将它添加到代码笔中
  • 感谢您的回答,但是当我尝试在 switch case 中显示弹出窗口时,它不起作用确实知道任何解决方案
  • case 'false': $ionicPopup.show({ title: 'Invalid Passcode!', template: '请输入有效密码。', scope: $scope, buttons: [ { text: 'Ok',输入:'button-positive',onTap: function(e) { } } ] });
猜你喜欢
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
  • 1970-01-01
相关资源
最近更新 更多