Я работаю над Angular 7
и механизм оповещения, используя Sweetalert2
с охраной canDeactivate
.
С export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate>
, я звоню dialogService
, чтобы подтвердить, если да или нет, вернувшисьreturn Observable.of(confirmation);
Я не знаю, как мы можем вернуть return Observable.of(confirmation);
из SweetAlert2
кода?
@Injectable()
export class DialogService {
confirmation;
confirm(message?: string): Observable<boolean> {
debugger;
const swalWithBootstrapButtons = Swal.mixin({
customClass: {
confirmButton: 'btn btn-success',
cancelButton: 'btn btn-danger'
},
buttonsStyling: false
});
swalWithBootstrapButtons.fire({
title: 'Are you sure?',
text: 'You wont be able to revert this!',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
reverseButtons: true
}).then((result) => {
if (result.value) {
swalWithBootstrapButtons.fire(
'Deleted!',
'Your file has been deleted.',
'success'
);
} else if (
/* Read more about handling dismissals below */
result.dismiss === Swal.DismissReason.cancel
) {
swalWithBootstrapButtons.fire(
'Cancelled',
'Your imaginary file is safe :)',
'error'
);
}
});
const confirmation = window.confirm(message || 'Are you sure?');
return Observable.of(confirmation);
}
}