Overview
TheNotificationsComponent is a standalone component that displays a list of notifications to the user in a dialog. It uses signal inputs and outputs for reactive data flow.
This component is typically used in conjunction with the
NotificationsStore to display application-wide notifications.Component definition
src/app/shared/ui/notifications.component.ts
Inputs
Signal input containing the array of notifications to display. Each notification has a
message (string) and type (‘info’ | ‘error’).Outputs
Event emitted when the user clicks the close button. Parent component should handle this to close/clear notifications.
Usage
Basic usage with NotificationsStore
Manual notification management
Conditional display based on type
The component automatically styles notifications based on their type:- Error notifications (
type: 'error') - Display witharia-invalid="true"for error styling - Info notifications (
type: 'info') - Display witharia-invalid="false"for normal styling
Template structure
The component renders a dialog with:- Header - “Notifications” title
- Body - List of notification inputs (disabled, with appropriate aria-invalid state)
- Footer - Close button
Modern Angular features
This component demonstrates several modern Angular patterns:- Standalone component - No module required
- Signal inputs -
input<Notification[]>()for reactive props - Output functions -
output()for type-safe events - OnPush change detection - Optimized performance
- Control flow syntax -
@forand@iffor template logic
Notification type
The component uses theNotification type from the domain layer:
Integration with error handling
This component is automatically used by the global error handler to display unhandled errors:- Error occurs anywhere in the app
- ErrorService catches it and adds to NotificationsStore
- NotificationsComponent displays the error to the user
- User clicks close to dismiss
Styling
The component uses semantic HTML elements (dialog, article, header, footer) and relies on your application’s global styles for appearance. The aria-invalid attribute allows you to style errors differently from info messages.
Related APIs
- NotificationsStore - State management for notifications
- Error handler - Global error handling that uses notifications
- Notification type - Type definition