试图将swal的第一个promise函数转换为observable并尝试使用cancel操作。有人可以帮助我的语法PLS。将Promise转换为Observable
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
}).then(function() {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
)
}, function (dismiss) {
// dismiss can be 'cancel', 'overlay',
// 'close', and 'timer'
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
到目前为止,我有以下几点:
export class DialogService {
confirm(title: string, message: string):Observable<any> {
return Observable.fromPromise(swal({
title: title,
text: message,
type: 'warning',
showCancelButton: true
}));
}; }
如何添加function (dismiss)
功能在上面?