javascript - 在 ionic 弹出窗口上传递值,但获取 MouseEvent

标签 javascript angularjs ionic-framework

我试图在 Ionic 弹出窗口上传递一个值,但每次我都会收到 MouseEvent {isTrusted: false, isIonicTap: true, screenX: 0, screenY: 0, clientX: 97…}日志 statementId 到控制台。我做错了什么?

View.html

<a class="button button-assertive" ng-controller="PopupController" ng-click="showRequestTakedownPopup(statement.id)"><i class="icon ion-sad"></i></a>

PopupController

function PopupController($scope, $ionicPopup, $timeout, $state) {
    $scope.showRequestTakedownPopup = function() {
        $ionicPopup.confirm({
            title: 'Request Takedown',
            content: 'Would you like to create a takedown request for this item?',
            scope: $scope,
            buttons:[
            {
                text: "Yes",
                type: 'button-positive',
                onTap: function(statementId){
                    console.log(statementId);
                    $state.go('sidemenu.takedown-justification', { "statement": statementId });
                }
            },
            {
                text: "No",
                type: 'button-positive',
                onTap: function(){
                }
            }
            ]
        })
    };
};

我已检查并确认 View 中的 statement.id 是正确的。

最佳答案

文档说 onTap

will by default close the popup and resolve the popup promise with its return value. If you wish to prevent the default and keep the popup open on button tap, call event.preventDefault() on the passed in tap event. (source)

所以你想要做的就是像调用 Promise 一样调用弹出窗口

   confirmPopup.then(function(res) {
     if(res) {
       console.log('You are sure');
     } else {
       console.log('You are not sure');
     }
   });

在您的情况下,以下内容应该有效:

$scope.showRequestTakedownPopup = function(statementId) {
    var myPopup = $ionicPopup.confirm({
        title: 'Request Takedown',
        content: 'Would you like to create a takedown request for this item?',
        scope: $scope,
        buttons:[
        {
            text: "Yes",
            type: 'button-positive',
            onTap: function(e){
                return statementId; 
            }
        },
        {
            text: "No",
            type: 'button-positive',
            onTap: function(){
            }
        }
        ]
    });
    myPopup.then(function(statementId) {
        console.log(statementId);
        $state.go('sidemenu.takedown-justification', { "statement": statementId });
    });

};

关于javascript - 在 ionic 弹出窗口上传递值,但获取 MouseEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36137763/

相关文章:

php - 在angularjs Controller 中的函数内调用函数

javascript - 使用环境变量/参数化config.xml

javascript - 按顺序解析 Javascript Promises 列表?

javascript - 测验应用程序 - 表单中提交按钮的 jquery 问题

javascript - AngularJS,附加到 $scope 的对象不会绑定(bind)到 html 元素

javascript - 封装Web服务数据的Angular服务

ionic-framework - ionic 后退按钮未显示在 Ionic 5 的工具栏中

cordova - 无法在 Ionic 4 应用程序中绕过 CORS

javascript - 限制第二次 ng-repeat 中显示的项目数

javascript - 单击匹配链接时切换单个 div 的属性