我试图在 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/