A generic Angular close button directive for dismissing content like modals and alerts.
Available in Other JavaScript Frameworks
CoreUI Angular Close Button Component is also available for Bootstrap, React, and Vue. Explore framework-specific implementations below:
On this page
Examples
Basic
Provide an option to dismiss or close a component with cCloseButton. Default styling is limited, but highly customizable. Modify the Sass variables to replace the default background-image.
import { Component } from '@angular/core';
import { ButtonCloseDirective } from '@coreui/angular';
@Component({
selector: 'docs-close-button',
templateUrl: './close-button.component.html',
imports: [ButtonCloseDirective]
})
export class CloseButtonComponent {}<button cButtonClose></button>Disabled
Disabled close buttons change their opacity. We’ve also applied pointer-events: none and user-select: none to preventing hover and active states from triggering.
import { Component } from '@angular/core';
import { ButtonCloseDirective } from '@coreui/angular';
@Component({
selector: 'docs-close-button-disabled',
templateUrl: './close-button-disabled.component.html',
imports: [ButtonCloseDirective]
})
export class CloseButtonDisabledComponent {}<button cButtonClose disabled></button>White variant
Change the default cCloseButton to be white with the white boolean property.
import { Component } from '@angular/core';
import { ButtonCloseDirective } from '@coreui/angular';
@Component({
selector: 'docs-close-button-white-variant',
templateUrl: './close-button-white-variant.component.html',
imports: [ButtonCloseDirective],
host: { class: 'bg-dark p-4 rounded-top-2 d-block', 'data-coreui-theme': 'dark' }
})
export class CloseButtonWhiteVariantComponent {}<button cButtonClose white></button>Sizing
Provide default, lg and sm size.
import { Component } from '@angular/core';
import { ButtonCloseDirective } from '@coreui/angular';
@Component({
selector: 'docs-close-button-sizing',
templateUrl: './close-button-sizing.component.html',
imports: [ButtonCloseDirective]
})
export class CloseButtonSizingComponent {}<button cButtonClose size="lg" ></button>
<button cButtonClose ></button>
<button cButtonClose size="sm" ></button>API reference
ButtonModule
import { ButtonModule } from '@coreui/angular';
@NgModule({
imports: [ButtonModule,]
})
export class AppModule() { }cButtonClose
directive
import { ButtonCloseDirective } from '@coreui/angular'