已经创建了甜蜜的警报作为单独的服务,我将其注入到我的服务中
这就是贴心的提醒服务
(function(){
'use strict';
angular.module('app.services')
.factory('SweetAlert', SweetAlertService);
SweetAlertService.$inject = [];
function SweetAlertService( ) {
var swal = window.swal;
//public methods
var self = {
swal: function ( arg1, arg2, arg3) {
if( typeof(arg2) === 'function' ) {
swal( arg1, function(isConfirm){
arg2(isConfirm);
}, arg3 );
} else {
swal( arg1, arg2, arg3 );
}
},
success: function(title, message) {
swal( title, message, 'success' );
},
confirm: function(title, message){
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Ok',
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true
},
function(isConfirm){
return isConfirm;
});
}
};
return self;
}
})();
然后在控制器中注入甜蜜警报服务,但这里它不返回确认选择值。
isConfirm 值未达到控制器中
(function() {
'use strict';
angular.module('app.controllers').controller("MasterController",
MasterController);
MasterController.$inject = ['$scope', '$window', '$http', 'SweetAlert'];
function MasterController($scope, $window, $http, SweetAlert) {
$scope.updateRow = function(row,event) {
vm.clear();
var updateRow = SweetAlert.confirm('Are you sure?');
if (updateRow) {
vm.save(row.entity);
}else{
event.preventDefault();
}
};
})();