Class AlertComponent

AlertComponent displays an alert message of type 'success' or 'danger' with customizable options. It can automatically hide after a set duration and includes a manual dismiss option.

app-alert-component

true

CommonModule

  • visible (boolean): Determines if the alert is visible. Default is false.
  • message (string): The message displayed in the alert.
  • type ('success' | 'danger'): Type of alert, either 'success' or 'danger'. Default is 'success'.
  • duration (number): Duration in milliseconds for the alert to remain visible before hiding. Default is 4000 ms.
  • textColor (string): Optional color for alert text. Default is 'black'.
  • onHide (function): Optional callback invoked when the alert is hidden.
  • ngOnChanges(changes: SimpleChanges): Lifecycle hook invoked on input changes; initiates auto-hide based on duration if visible is true.
  • handlePress(): Manually hides the alert by invoking the onHide callback.
<app-alert-component
[visible]="showAlert"
[message]="alertMessage"
[type]="alertType"
[duration]="5000"
[textColor]="alertTextColor"
[onHide]="onAlertHide">
</app-alert-component>

Implements

  • OnChanges

Constructors

Methods

  • 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.

    Parameters

    • changes: SimpleChanges

      The changed properties.

    Returns void

Properties

visible: boolean = false
message: string = ''
type: "success" | "danger" = 'success'
duration: number = 4000
textColor: string = 'black'
onHide: (() => void)
alertType: "success" | "danger" = 'success'