本文介绍了确认值未从甜蜜警报服务中返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已经创建了甜蜜警报作为单独的服务,然后将其注入到我的服务中
Had created sweet alert as seperate service and Im injecting that inro my service
这是甜蜜的警报服务
(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值未到达控制器中
Then in the controller the sweet alert service is injected, but here its not returning the confirm select value.isConfirm value is not reaching in the controller
(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();
}
};
})();
推荐答案
我认为您应该更改sweeet alert
确认框的实现.甜蜜警报的confirm
方法实现方式,您需要将callback
传递给confirm
方法并在该位置执行.
I think you should change implementation of sweeet alert
confirm box. The way confirm
method of sweet alert implement, you need to pass pass a callback
to execute to confirm
method and execute over there.
confirm: function(title, message, callback) {
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) {
callback(isConfirm)
});
};
控制器
$scope.updateRow = function(row, event) {
vm.clear();
SweetAlert.confirm('Are you sure?', null, function(isConfirmed) {
if (isConfirmed) {
vm.save(row.entity);
} else {
event.preventDefault();
}
});
};
这篇关于确认值未从甜蜜警报服务中返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!