trying to convert swal's first promise function to observable and trying to use the cancel action. Can someone help me with the syntax pls.
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'
)
}
})
So far I have the following:
export class DialogService {
confirm(title: string, message: string):Observable<any> {
return Observable.fromPromise(swal({
title: title,
text: message,
type: 'warning',
showCancelButton: true
}));
}; }
How do I add the function (dismiss)
function in the above?
I'm not sure that swal
use native Promise
api, I think it uses A promise library for JavaScript like q or something else.
export class DialogService {
confirm(title: string, message: string):Observable<any> {
return Observable.create( (observer: any) => {
swal({
title: title,
text: message,
type: 'warning',
showCancelButton: true
}).then((data)=>{
observer.next(data);
},(reason)=>{
observer.error(reason);
})
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With