CoreUI Angular Logo
Framework:
  • JavaScript / Vanilla JS
  • React.js
  • Vue.js
Getting startedIntroductionSupport CoreUICustomizeSassOptionsCSS VariablesLayoutBreakpointsContainersGridColumnsGuttersFormsOverviewDate PickerPRODate Range PickerPROForm ControlSelectMulti SelectPROChecks & RadiosPassword InputPRORangeRange SliderPRORatingPROStepperPROInput GroupFloating LabelsLayoutTime PickerPROValidationComponentsAccordionAlertAvatarBadgeBreadcrumbButtonButton GroupCalendarPROCalloutCardCarouselClose buttonCollapseDropdownFooterHeaderImageList GroupLoading ButtonPROModalNavNavbarOffcanvasPaginationPlaceholderPopoverProgressSmart PaginationPROSmart TablePROSidebarSpinnerTableTabsNewToastTooltipWidgetsIconsChartsTemplatesNewAdmin & DashboardDownloadInstallationCustomizeContentMigrationv4 → v5v3 → v4Angular version


DownloadHire UsGet CoreUI PRO
On this page

    Angular Alert Component

    Angular alert component gives contextual feedback information for common user operations. The alert component is delivered with a bunch of usable and adjustable alert messages.

    Examples

    Colors

    Angular Alert is prepared for any length of text, as well as an optional close button. For a styling, use one of the required contextual color props (e.g., primary). For inline dismissal, use the dismissing prop.

    A simple primary alert—check it out!A simple secondary alert—check it out!A simple success alert—check it out!A simple danger alert—check it out!A simple warning alert—check it out!A simple info alert—check it out!A simple light alert—check it out!A simple dark alert—check it out!
    Loading...
    import { Component } from '@angular/core';
    import { AlertComponent } from '@coreui/angular';
    
    @Component({
      selector: 'docs-alert01-example',
      templateUrl: './alert01.component.html',
      standalone: true,
      imports: [AlertComponent]
    })
    export class Alert01Component {}
    

    Link color

    Use the cAlertLink directive class to quickly provide matching colored links within any alert.

    A simple primary alert with an example link. Give it a click if you like. A simple secondary alert with an example link. Give it a click if you like. A simple success alert with an example link. Give it a click if you like. A simple danger alert with an example link. Give it a click if you like. A simple warning alert with an example link. Give it a click if you like. A simple info alert with an example link. Give it a click if you like. A simple light alert with an example link. Give it a click if you like. A simple dark alert with an example link. Give it a click if you like.
    Loading...
    import { Component } from '@angular/core';
    import { RouterLink } from '@angular/router';
    import { AlertComponent, AlertLinkDirective } from '@coreui/angular';
    
    @Component({
      selector: 'docs-alert02-example',
      templateUrl: './alert02.component.html',
      standalone: true,
      imports: [
        AlertComponent,
        AlertLinkDirective,
        RouterLink
      ]
    })
    export class Alert02Component {}
    

    Additional content

    Alert can also incorporate supplementary HTML elements like heading with cAlertHeading, paragraph, and divider.

    Well done!

    Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.


    Whenever you need to, be sure to use margin utilities to keep things nice and tidy.

    Loading...
    import { Component } from '@angular/core';
    import { AlertComponent, AlertHeadingDirective } from '@coreui/angular';
    
    @Component({
      selector: 'docs-alert03-example',
      templateUrl: './alert03.component.html',
      standalone: true,
      imports: [AlertComponent, AlertHeadingDirective]
    })
    export class Alert03Component {}
    

    Dismissing

    Alerts can also be easily dismissed. Just add the dismissible prop and fade for animation. To remove an alert from the DOM, you can use *ngIf directive.

    Go right ahead and click that dismiss over there on the right.
    Loading...
    import { Component } from '@angular/core';
    import { AlertComponent, ButtonDirective } from '@coreui/angular';
    
    @Component({
      selector: 'docs-alert04-example',
      templateUrl: './alert04.component.html',
      standalone: true,
      imports: [AlertComponent, ButtonDirective]
    })
    export class Alert04Component {
    
      visible = true;
      dismissible = true;
    
    }
    

    Custom template

    Use alertButtonCloseTemplate to customize close button.

    Go right ahead and click that dismiss over there on the right.
    Loading...
    import { Component } from '@angular/core';
    import { AlertComponent, ButtonCloseDirective, ButtonDirective, TemplateIdDirective } from '@coreui/angular';
    
    @Component({
      selector: 'docs-alert05-example',
      templateUrl: './alert05.component.html',
      standalone: true,
      imports: [AlertComponent, TemplateIdDirective, ButtonCloseDirective, ButtonDirective]
    })
    export class Alert05Component {
    
      visible = true;
    
      onVisibleChange(eventValue: boolean) {
        this.visible = eventValue;
      }
    
      onResetDismiss() {
        this.visible = true;
      }
    }
    

    Icons

    You can use Icons and flexbox utilities to create alerts with icons.

    An example alert with cIcon
    An example alert with svg icon

    An example primary alert with an icon
    An example success alert with an icon
    An example warning alert with an icon
    An example danger alert with an icon
    Loading...
    import { Component } from '@angular/core';
    import { cilCheck } from '@coreui/icons';
    import { AlertComponent } from '@coreui/angular';
    import { IconDirective } from '@coreui/icons-angular';
    
    @Component({
      selector: 'docs-alert06-example',
      templateUrl: './alert06.component.html',
      standalone: true,
      imports: [AlertComponent, IconDirective]
    })
    export class Alert06Component {
    
      icons = { cilCheck };
    
    }
    

    API reference

    Alert Module

    import { AlertModule } from '@coreui/angular';
    
    @NgModule({ 
     imports: [AlertModule,]
    })
    export class AppModule(){}
    

    c-alert

    component

    Inputs
    name description type default
    color Sets the color context of the component string 'primary'
    dismissible adds a close button to alert for self dismiss boolean false
    fade adds optional animation for dismissible alert boolean false
    variant Set the alert variant to a solid string: 'solid' undefined
    visible toggle visibility of alert component boolean true
    Outputs
    name description type
    visibleChange Event triggered on the alert dismiss. boolean

    cAlertHeading

    directive

    cAlertLink

    directive

    • GitHub
    • Twitter
    • Support
    • CoreUI (Vanilla)
    • CoreUI for React.js
    • CoreUI for Vue.js

    CoreUI for Angular is Open Source UI Components Library for Angular.

    Currently v5.5.2 Code licensed MIT , docs CC BY 3.0 .
    CoreUI PRO requires a commercial license.