AlertComponent - Toast-style notification component for success and error messages
Displays toast-style alert messages with automatic dismiss timer and manual close option. Supports three levels of customization:
Key Features:
Basic Usage:
<app-alert-component [visible]="showAlert" [message]="'Operation completed successfully!'" [type]="'success'" [duration]="5000" [onHide]="handleAlertClose"></app-alert-component> Copy
<app-alert-component [visible]="showAlert" [message]="'Operation completed successfully!'" [type]="'success'" [duration]="5000" [onHide]="handleAlertClose"></app-alert-component>
Style Customization:
<app-alert-component [visible]="showError" [message]="'An error occurred'" [type]="'danger'" [textColor]="'white'" [alertStyle]="{ backgroundColor: '#dc3545', border: '2px solid #c82333', borderRadius: '8px', padding: '15px 20px' }" [onHide]="handleErrorClose"></app-alert-component> Copy
<app-alert-component [visible]="showError" [message]="'An error occurred'" [type]="'danger'" [textColor]="'white'" [alertStyle]="{ backgroundColor: '#dc3545', border: '2px solid #c82333', borderRadius: '8px', padding: '15px 20px' }" [onHide]="handleErrorClose"></app-alert-component>
Custom Template Override:
<app-alert-component [visible]="showAlert" [message]="alertMessage" [type]="alertType" [customTemplate]="customAlertTemplate" [onHide]="handleAlertClose"></app-alert-component><ng-template #customAlertTemplate let-visible="visible" let-message="message" let-type="type"> <div class="custom-alert" [class.success]="type === 'success'" [class.danger]="type === 'danger'"> <i [class]="type === 'success' ? 'fa fa-check-circle' : 'fa fa-exclamation-triangle'"></i> <span>{{ message }}</span> <button (click)="handleAlertClose()">×</button> </div></ng-template> Copy
<app-alert-component [visible]="showAlert" [message]="alertMessage" [type]="alertType" [customTemplate]="customAlertTemplate" [onHide]="handleAlertClose"></app-alert-component><ng-template #customAlertTemplate let-visible="visible" let-message="message" let-type="type"> <div class="custom-alert" [class.success]="type === 'success'" [class.danger]="type === 'danger'"> <i [class]="type === 'success' ? 'fa fa-check-circle' : 'fa fa-exclamation-triangle'"></i> <span>{{ message }}</span> <button (click)="handleAlertClose()">×</button> </div></ng-template>
app-alert-component
true
CommonModule
visible - Whether the alert is currently visible. Default: false
false
message - The message text to display in the alert. Default: ''
''
type - Alert type ('success' or 'danger') affecting color scheme. Default: 'success'
'success'
duration - Auto-dismiss duration in milliseconds. Default: 4000
4000
textColor - Color of the message text. Default: 'black'
'black'
onHide - Callback function invoked when alert is dismissed (auto or manual). Default: undefined
undefined
alertStyle - Custom CSS styles to apply to the alert container. Default: undefined
customTemplate - Custom TemplateRef to completely replace default alert template. Default: undefined
ngOnChanges - Handles input changes and triggers auto-dismiss timer when visible
handlePress - Manually dismisses the alert by invoking onHide callback
A callback method that is invoked immediately after the default change detector has checked data-bound properties if at least one has changed, and before the view and content children are checked.
The changed properties.
Optional
AlertComponent - Toast-style notification component for success and error messages
Component
Description
Displays toast-style alert messages with automatic dismiss timer and manual close option. Supports three levels of customization:
Key Features:
Example
Basic Usage:
Example
Style Customization:
Example
Custom Template Override:
Selector
app-alert-component
Standalone
true
Imports
CommonModule
Input
visible - Whether the alert is currently visible. Default:
false
Input
message - The message text to display in the alert. Default:
''
Input
type - Alert type ('success' or 'danger') affecting color scheme. Default:
'success'
Input
duration - Auto-dismiss duration in milliseconds. Default:
4000
Input
textColor - Color of the message text. Default:
'black'
Input
onHide - Callback function invoked when alert is dismissed (auto or manual). Default:
undefined
Input
alertStyle - Custom CSS styles to apply to the alert container. Default:
undefined
Input
customTemplate - Custom TemplateRef to completely replace default alert template. Default:
undefined
Method
ngOnChanges - Handles input changes and triggers auto-dismiss timer when visible
Method
handlePress - Manually dismisses the alert by invoking onHide callback