I have two components. In the first one on successful server response I want to do the following:
this.router.navigate(['']);
this.snackBarMessage = 'Successfully submitted';
Then the page is being redirected to another component and I would like to show the snackBarMessage message just there e.g (ngOnInit())
Something like that:
this.snackBarService.openSnackBar(snackBarMessage, 'Close', 9999999);
My snackBarService:
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material';
@Injectable({
providedIn: 'root'
})
export class SnackBarService {
constructor(private matSnackBar: MatSnackBar) { }
openSnackBar(message: string, action: string, duration?: number) {
this.matSnackBar.open(message, action, { duration });
}
}
How can I achieve that? How can I pass snackBarMessage to another component after navigation?