我最终得到以下代码:
MetronicApp.directive('confirmClick', ['SweetAlert',
function(SweetAlert) {
return {
priority: 100,
restrict: 'A',
scope: {
confirmClick: '&'
},
link: {
pre: function(scope, element, attr) {
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.confirmedClick;
element.bind('click touchstart', function(event) {
SweetAlert.swal({
title: "Are you sure?",
text: "Your will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: true
},
function(isConfirm) {
if (isConfirm) {
scope.confirmClick();
}
else{
return false;
}
});
});
}
}
};
}
]);