Caroline
asked on 24 Jan 2024, 06:41 PM
| edited on 24 Jan 2024, 06:42 PM
Hi there,
Is there any built-in way to close a snackbar/notification bar if the user navigates to another page?
Or, if this isn't the right use case for the notification bar, could someone point me to a better one?
Thank you!
1 Answer, 1 is accepted
0
Zornitsa
Telerik team
answered on 26 Jan 2024, 04:08 PM
Hi Caroline,
The Notification component can be closed programmatically by utilizing a NotificationRef instance, and then using its built-in hide() method. In your case, this method can be called when the corresponding navigation, with which you desire to hide the Notification, is performed.
On the other hand, if the Notification is initialized in a component that is being destroyed with the navigation, the developer may call the hide() function in the ngOnDestroy() method of the respective component.
Another approach that may be suitable for your scenario is appending the Notification to a dynamic container that is destroyed at some point either through the route navigation, or by the application logic. More information regarding this approach and a runnable example is available in the following article: