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 & DasardDownloadInstallationCustomizeContentMigrationv4 → v5v3 → v4Angular version


DownloadHire UsGet CoreUI PRO
On this page

    Angular Toast Component

    Push notifications to your visitors with an Angular toast, a lightweight and easily customizable alert message.

    Overview

    Angular toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They’re built with flexbox, so they’re easy to align and position.

    Things to know when using the toast plugin:

    • Toasts are opt-in for performance reasons, so you must initialize them yourself.
    • Toasts will automatically hide if you do not specify autohide: false.

    Examples

    Basic toast

    To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use display: flex, allowing easy alignment of content thanks to our margin and flexbox utilities.

    Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your "toasted" content and strongly encourage a dismiss button.

    CoreUI for Angular This is a static toast message
    Loading...
    import { Component } from '@angular/core';
    import { ToastBodyComponent, ToastComponent, ToastHeaderComponent } from '@coreui/angular';
    import { ToastSampleIconComponent } from './toast-sample-icon.component';
    
    @Component({
      selector: 'docs-toast01',
      templateUrl: './toast01.component.html',
      standalone: true,
      imports: [ToastComponent, ToastHeaderComponent, ToastSampleIconComponent, ToastBodyComponent]
    })
    export class Toast01Component {}
    
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'toast-sample-icon',
      template: `<svg
        class="rounded me-2"
        width="20"
        height="20"
        xmlns="http://www.w3.org/2000/svg"
        preserveAspectRatio="xMidYMid slice"
        focusable="false"
        role="img"
      >
        <rect width="100%" height="100%" fill="#007aff"></rect>
      </svg>`,
      standalone: true
    })
    export class ToastSampleIconComponent {}
    
    CoreUI for Angular

    This is static toast message in a toaster

    Loading...
    import { Component, signal } from '@angular/core';
    import {
      ButtonDirective,
      ProgressComponent,
      ToastBodyComponent,
      ToastComponent,
      ToasterComponent,
      ToastHeaderComponent
    } from '@coreui/angular';
    import { ToastSampleIconComponent } from './toast-sample-icon.component';
    
    @Component({
      selector: 'docs-toast02',
      templateUrl: './toast02.component.html',
      standalone: true,
      imports: [
        ButtonDirective,
        ProgressComponent,
        ToasterComponent,
        ToastComponent,
        ToastHeaderComponent,
        ToastSampleIconComponent,
        ToastBodyComponent
      ]
    })
    export class Toast02Component {
      position = 'top-end';
      visible = signal(false);
      percentage = signal(0);
    
      toggleToast() {
        this.visible.update((value) => !value);
      }
    
      onVisibleChange($event: boolean) {
        this.visible.set($event);
        this.percentage.set(this.visible() ? this.percentage() : 0);
      }
    
      onTimerChange($event: number) {
        this.percentage.set($event * 25);
      }
    }
    
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'toast-sample-icon',
      template: `<svg
        class="rounded me-2"
        width="20"
        height="20"
        xmlns="http://www.w3.org/2000/svg"
        preserveAspectRatio="xMidYMid slice"
        focusable="false"
        role="img"
      >
        <rect width="100%" height="100%" fill="#007aff"></rect>
      </svg>`,
      standalone: true
    })
    export class ToastSampleIconComponent {}
    
    Loading...
    import { Component, viewChild } from '@angular/core';
    
    import { ButtonDirective, ToasterComponent, ToasterPlacement } from '@coreui/angular';
    import { AppToastSampleComponent } from './toast-sample.component';
    
    @Component({
      selector: 'docs-toast03',
      templateUrl: './toast03.component.html',
      standalone: true,
      imports: [ToasterComponent, ButtonDirective]
    })
    export class Toast03Component {
      placement = ToasterPlacement.TopCenter;
    
      readonly toaster = viewChild(ToasterComponent);
    
      addToast() {
        const options = {
          title: `CoreUI for Angular Toast`,
          delay: 5000,
          placement: this.placement,
          color: 'info',
          autohide: true
        };
        const componentRef = this.toaster()?.addToast(AppToastSampleComponent, { ...options });
      }
    }
    
    Loading...
    Loading...
    Loading...

    Translucent

    Toasts are slightly translucent to blend in with what's below them.

    CoreUI for Angular 7 min agoThis is a toast message
    Loading...
    Loading...
    Loading...

    Stacking

    You can stack toasts by wrapping them in a c-toaster container, which will vertically add some spacing.

    CoreUI for Angular 7 min agoThis is a toast messageCoreUI for Angular 5 min agoThis is a toast message
    Loading...
    Loading...
    Loading...

    Custom content

    Customize your toasts by removing sub-components, tweaking them with utilities, or by adding your own markup. Here we've created a simpler toast by removing the default c-toast-header, adding a cButtonClose, and using some flexbox utilities to adjust the layout.

    Hello, world! This is a toast message.
    Loading...
    Loading...

    Alternatively, you can also add additional controls and components to toasts.

    Hello, world! This is a toast message.
    Loading...
    import { Component } from '@angular/core';
    import {
      ButtonDirective,
      ToastBodyComponent,
      ToastCloseDirective,
      ToastComponent,
      ToasterComponent
    } from '@coreui/angular';
    
    @Component({
      selector: 'docs-toast07',
      templateUrl: './toast07.component.html',
      standalone: true,
      imports: [ToasterComponent, ToastComponent, ToastBodyComponent, ButtonDirective, ToastCloseDirective]
    })
    export class Toast07Component {}
    

    Color schemes

    Building on the above example, you can create different toast color schemes with our color and background utilities. Here we've set color="primary" and added .text-white class to the c-toast, and then set white property to our close button. For a crisp edge, we remove the default border with .border-0.

    Hello, world! This is a toast message.
    Loading...
    Loading...

    Placement

    Place toasts where need them to show. The top right or top middle is often used for notifications.

    CoreUI for AngularJust nowSee? Just like this.CoreUI for Angular2 secs agoHeads up, toasts will stack automatically
    Loading...
    Loading...
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'toast-sample-icon',
      template: `<svg
        class="rounded me-2"
        width="20"
        height="20"
        xmlns="http://www.w3.org/2000/svg"
        preserveAspectRatio="xMidYMid slice"
        focusable="false"
        role="img"
      >
        <rect width="100%" height="100%" fill="#007aff"></rect>
      </svg>`,
      standalone: true
    })
    export class ToastSampleIconComponent {}
    

    API reference

    Toast Module

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

    c-toast

    component

    exportAs: cToast

    Inputs
    namedescriptiontypedefault
    autohideAuto hide the toast.booleantrue
    colorSets the color context of the component to one of CoreUI’s themed colors.Colorsundefined
    delayDelay hiding the toast (ms).number5000
    fadeApply fade transition to the toast.booleantrue
    visibleToggle the visibility of component.booleanfalse
    Outputs
    namedescriptiontype
    visibleChangeEvent emitted on visible change.boolean
    timerEvent emitted on clock tick (secs).number

    c-toast-body

    component

    exportAs: cToastBody

    c-toast-header

    component

    exportAs: cToastHeader

    Inputs
    namedescriptiontypedefault
    closeButtonAdd close button to the toast header.booleantrue

    c-toaster

    component

    exportAs: cToaster

    Inputs
    namedescriptiontypedefault
    placementToaster placement.stringtop-end
    positionToaster position.string | absolute | fixed | staticabsolute

    cToastClose

    directive

    exportAs: cToastClose

    Inputs
    namedescriptiontypedefault
    cToastCloseToast to close.ToastComponentrequired
    • 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.