我正在写一个小写字母,接受名称作为输入。当用户单击确认时,我需要先调用一个API,然后根据其成功/错误来决定是否关闭swal。无论我做什么,只要我点击确认,小瓶就会关闭。我已经编写了以下代码:
swal({
title: "Are you sure you want to do this?",
type: 'warning',
text: 'Please enter a name',
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, Go Ahead!",
cancelButtonText: "No",
input: 'text',
inputPlaceholder: 'Enter Name',
inputValidator: (value) => {
debugger;
if(!value){
return !value && 'Please enter a name'
}
},
preConfirm: function(textarea) {
return new Promise(function(resolve, reject) {
$http.post('/api/myApi', {'Name' : $('input[placeholder="Enter Name"]').val()}).
success(function(response, status, headers, config) {
resolve();
}).
error(function(response) {
reject('Name already exists');
});
});
},
allowOutsideClick: false
}).then((result) => {
if (result.value) {
///do something
}
}).catch(swal.noop);
有人可以让我知道我在这里做错了什么吗,或者什至可能是我想要达到的目标?