Good evening, I have a question that I want to ask the question is that I want my angular application to automatically reload after a snackbar appears that lasts a certain time, this after executing a delete action.
export class PrtgFormService {
constructor(private dialog: MatDialog,
private snackBar: MatSnackBar,) { }
config: MatSnackBarConfig = {
duration: 4000,
horizontalPosition: 'center',
verticalPosition: 'bottom',
}
success(msg: any) {
this.config['panelClass']='equipo_success';
this.snackBar.open(msg, '',this.config);
}
}
// Funcion que genera la ventana modal para confirmar eliminar algun elemento/objeto en particular.Recibe como parametro el objeto en cuestion.
onDelete(element:any) {
this.msgEquipo='¿Esta seguro que desear eliminar este equipo?';
this.PrtgServiceForm.openConfirmDialogDelete(this.msgEquipo).afterClosed().subscribe(res =>{ // Si en caso afirmativo se presiona el boton SI en el dialogo de eliminar equipo, la variable res=true y se hace la peticion al servicio HTTP Delete.
if(res){
this.PrtgService.deleteEquipo(element).subscribe();
this.msg="Equipo Eliminado con exito";
this.PrtgServiceForm.success(this.msg);
console.log(res)
}
});
}
You can use afterDismissed
method of mat-snackbar. use this link for more details.
success(msg: any) {
this.config['panelClass'] = 'equipo_success';
let snackBarRef = this.snackBar.open(msg, '', this.config);
snackBarRef.afterDismissed().subscribe(() => {
// Reload your application here
});
}
In your onDelete method maybe you can use
onDelete(element:any) {
this.msgEquipo='¿Esta seguro que desear eliminar este equipo?';
this.PrtgServiceForm.openConfirmDialogDelete(this.msgEquipo).afterClosed().subscribe(res =>{ // Si en caso afirmativo se presiona el boton SI en el dialogo de eliminar equipo, la variable res=true y se hace la peticion al servicio HTTP Delete.
if(res){
this.PrtgService.deleteEquipo(element).subscribe();
this.msg="Equipo Eliminado con exito";
this.PrtgServiceForm.success(this.msg);
console.log(res)
location.reload();
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.