# bootstrap-ng > Angular 21.2+ components for Bootstrap 6. Standalone components and directives with signal inputs and outputs. They render Bootstrap's own markup through attribute selectors such as `
`, and use no Bootstrap JavaScript. Install with `npm install bootstrap-ng bootstrap` and add Bootstrap's CSS to the app. Selectors use the `bs` prefix and exported classes start with `Bs` (for example `BsAlert`). Bootstrap 6 markup differs from Bootstrap 5: buttons use `.btn-solid`, `.btn-outline` or `.btn-subtle` with a `.theme-*` class, dialogs use the native `` element and accordions use `
`. This file contains every page of the bootstrap-ng documentation. [llms.txt](https://bootstrap-ng.com/llms.txt) lists the pages with a short summary of each. # Introduction Source: Add bootstrap-ng to an Angular application and use your first component. > bootstrap-ng targets **Bootstrap 6**, which is in alpha. Class names and markup can change before the stable release. bootstrap-ng follows each Bootstrap 6 pre-release. ## Requirements - Angular 21.2 or later - Bootstrap 6 CSS Form controls also work with Signal Forms (`@angular/forms/signals`), which are experimental in Angular 21 and stable from Angular 22. bootstrap-ng does not use Bootstrap's JavaScript. Do not add `bootstrap.bundle.js` to your application. It would handle the same elements twice. ## Install ```sh npm install bootstrap-ng bootstrap@next @floating-ui/dom ``` Bootstrap 6 is published under the `next` tag until its stable release, so a plain `npm install bootstrap` would install Bootstrap 5. [Floating UI](https://floating-ui.com/) positions tooltips, popovers and menus, as it does in Bootstrap. bootstrap-ng only needs Bootstrap's CSS, never its JavaScript, so the `bootstrap` package is an optional peer dependency. Skip it if you [load the CSS from a CDN](https://bootstrap-ng.com/getting-started/#css): ```sh npm install bootstrap-ng @floating-ui/dom ``` ## Add Bootstrap's CSS Add the compiled CSS to the `styles` array in `angular.json`: ```json "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.scss" ] ``` Or, to customize Bootstrap with Sass, import its source in your global stylesheet: ```scss @use 'bootstrap/scss/bootstrap'; ``` Or load it from the jsDelivr CDN in the `` of `src/index.html`, as this site does. You don't need the `bootstrap` package then. bootstrap-ng supports Bootstrap 6.0.0-alpha.2 and later 6.x releases: ```html ``` ## Use a component Every component and directive is standalone. Import the ones you need into your component's `imports`: ```ts import { Component } from '@angular/core'; import { BsAlert, BsButton } from 'bootstrap-ng'; @Component({ selector: 'app-root', imports: [BsAlert, BsButton], template: `

bootstrap-ng is ready.

`, }) export class App {} ``` Follow the [Quickstart](https://bootstrap-ng.com/getting-started/quickstart/) to build a small page step by step, or read the [conventions](https://bootstrap-ng.com/getting-started/conventions/) to learn how the API is designed, then browse the components in the sidebar. --- # Quickstart Source: Create a new Angular application with bootstrap-ng and build a small page with a dialog and a toast. ## 1. Create an application You need Node.js and npm. Create an application with the Angular CLI and choose Sass for styles: ```sh npx @angular/cli@latest new my-app --style=scss cd my-app ``` ## 2. Install bootstrap-ng and Bootstrap Bootstrap 6 is published under the `next` tag until its stable release. Floating UI positions tooltips, popovers and menus. ```sh npm install bootstrap-ng bootstrap@next @floating-ui/dom ``` ## 3. Add Bootstrap's styles Import Bootstrap at the top of `src/styles.scss`: ```scss @use 'bootstrap/scss/bootstrap'; ``` Do not add Bootstrap's JavaScript. bootstrap-ng implements all of its behavior in Angular. ## 4. Build a page Replace `src/app/app.ts` with a component that imports the parts it uses: ```ts import { Component, inject, signal } from '@angular/core'; import { BsButton, BsCloseButton, BsDialog, BsDialogClose, BsFormControl, BsFormField, BsFormLabel, BsToaster, } from 'bootstrap-ng'; @Component({ selector: 'app-root', imports: [ BsButton, BsCloseButton, BsDialog, BsDialogClose, BsFormControl, BsFormField, BsFormLabel, ], templateUrl: './app.html', }) export class App { private readonly toaster = inject(BsToaster); protected readonly name = signal(''); protected save(): void { this.toaster.show({ title: 'Saved', body: `Hello, ${this.name() || 'friend'}!` }); } } ``` And replace `src/app/app.html` with its template: ```html

Hello, bootstrap-ng

Your name

``` The button opens a native ``, which traps focus and closes with `Escape`. Saving closes it and shows a toast through `BsToaster`. ## 5. Run it ```sh ng serve ``` Open `http://localhost:4200` and select **Edit name**. ## Next steps - Read the [conventions](https://bootstrap-ng.com/getting-started/conventions/) that every component follows. - Change colors and switch to dark mode in [Theming](https://bootstrap-ng.com/getting-started/theming/). - Build forms with [fields, controls and validation](https://bootstrap-ng.com/forms/overview/). - Browse the components in the sidebar. --- # Conventions Source: The rules that every bootstrap-ng component follows. ## Bootstrap markup, not wrappers Most components use attribute selectors on the element that Bootstrap styles. The rendered DOM is the same as in Bootstrap's own documentation, so selectors such as `.accordion > .accordion-item` keep working. ```html
…
…
``` ## Themes and variants Bootstrap 6 replaces color-named classes such as `.btn-primary` with a variant class and a `.theme-*` class. bootstrap-ng exposes these as separate `variant` and `theme` inputs. The themes are `primary`, `accent`, `success`, `danger`, `warning`, `info`, `inverse` and `secondary`. ## Signals and two-way binding Inputs use `input()` and outputs use `output()`. State that the user can change, such as whether a collapse is open, is a `model()`, so you can bind it both ways: ```html
…
… ``` ## Template references Components with behavior have an `exportAs` name. Use a template reference to call their methods: ```html … ``` ## Imports Import single components so that unused ones are removed from your bundle. For quick prototypes, `BOOTSTRAP_NG` contains everything: ```ts import { BOOTSTRAP_NG } from 'bootstrap-ng'; @Component({ imports: [BOOTSTRAP_NG], … }) ``` Each component also has its own entry point, named after its folder, such as `bootstrap-ng/button` or `bootstrap-ng/datepicker`. Importing from `bootstrap-ng` gives the same bundle: a component that only lazy routes use is loaded with those routes, not up front. ```ts import { BsButton } from 'bootstrap-ng/button'; import { BsDatepicker } from 'bootstrap-ng/datepicker'; ``` ### Grouped imports Components made of several directives also export an array with all of them, so one import covers the whole component: ```ts import { BS_TABS } from 'bootstrap-ng/tabs'; @Component({ // Same as [BsTabs, BsTab, BsTabContent, BsTabPane] imports: [BS_TABS], … }) ``` | Array | Entry point | Contains | | --- | --- | --- | | [`BS_ACCORDION`](https://bootstrap-ng.com/components/accordion/#api) | `bootstrap-ng/accordion` | BsAccordion, BsAccordionItem, BsAccordionHeader, BsAccordionBody | | [`BS_BREADCRUMB`](https://bootstrap-ng.com/components/breadcrumb/#api) | `bootstrap-ng/breadcrumb` | BsBreadcrumb, BsBreadcrumbLink | | [`BS_BUTTON_GROUP`](https://bootstrap-ng.com/components/button-group/#api) | `bootstrap-ng/button-group` | BsButtonGroup, BsButtonToolbar | | [`BS_CAROUSEL`](https://bootstrap-ng.com/components/carousel/#api) | `bootstrap-ng/carousel` | BsCarousel, BsCarouselItem, BsCarouselPrev, BsCarouselNext, BsCarouselIndicator, BsCarouselPlayPause | | [`BS_COLLAPSE`](https://bootstrap-ng.com/components/collapse/#api) | `bootstrap-ng/collapse` | BsCollapse, BsCollapseToggle | | [`BS_DIALOG`](https://bootstrap-ng.com/components/dialog/#api) | `bootstrap-ng/dialog` | BsDialog, BsDialogClose | | [`BS_DRAWER`](https://bootstrap-ng.com/components/drawer/#api) | `bootstrap-ng/dialog` | BsDrawer, BsDrawerToggle, BsDialogClose | | [`BS_FORMS`](https://bootstrap-ng.com/forms/overview/#api) | `bootstrap-ng` | Form controls, field layout and validation directives, except BsTypeahead | | [`BS_LIST_GROUP`](https://bootstrap-ng.com/components/list-group/#api) | `bootstrap-ng/list-group` | BsListGroup, BsListGroupItem | | [`BS_MENU`](https://bootstrap-ng.com/components/menu/#api) | `bootstrap-ng/menu` | BsMenu, BsMenuToggle, BsSubmenu | | [`BS_NAV`](https://bootstrap-ng.com/components/nav/#api) | `bootstrap-ng/nav` | BsNav, BsNavLink, BsNavOverflow | | [`BS_PROGRESS`](https://bootstrap-ng.com/components/progress/#api) | `bootstrap-ng/progress` | BsProgress, BsProgressStacked | | [`BS_STEPPER`](https://bootstrap-ng.com/components/stepper/#api) | `bootstrap-ng/stepper` | BsStepper, BsStepperItem | | [`BS_TABS`](https://bootstrap-ng.com/components/tab/#api) | `bootstrap-ng/tabs` | BsTabs, BsTab, BsTabContent, BsTabPane | | [`BS_TOAST`](https://bootstrap-ng.com/components/toasts/#api) | `bootstrap-ng/toast` | BsToast, BsToastClose | ## Accessibility Components set the ARIA roles and states that Bootstrap documents, such as `aria-expanded` on collapse toggles and `role="progressbar"` on progress bars. You still give labels: for example, `aria-label` on icon buttons and progress bars. See [Accessibility](https://bootstrap-ng.com/getting-started/accessibility/) for keyboard support, focus management and live announcements. --- # Theming Source: Theme colors, light and dark color modes, and customizing Bootstrap in an Angular application. ## Theme colors Bootstrap 6 colors a component with a `.theme-*` class. Components that support it have a `theme` input that sets this class for you, and you can bind it like any other input: ```html
…
… ``` The themes are `primary`, `accent`, `success`, `danger`, `warning`, `info`, `inverse` and `secondary`. Use the `BsTheme` type to pass a theme through your own components: ```ts import { BsTheme } from 'bootstrap-ng'; readonly theme = input('primary'); ``` ## Color modes Bootstrap 6 builds its colors with the CSS `light-dark()` function, so every page follows the visitor's system setting for light or dark mode with no extra code. bootstrap-ng components use Bootstrap's color tokens, so they switch with the page. To force a mode for the whole application, set `data-bs-theme` on the `` element in `src/index.html`: ```html … ``` Set it on any other element to force a mode for just that part of the page: ```html
…
``` Popups such as the [datepicker](https://bootstrap-ng.com/forms/datepicker/) calendar open in the top layer, outside the element they belong to. The datepicker's `colorMode` input forces a mode for its calendar. ### Switching modes To let people choose a mode, set the attribute from a component. Keep the choice in a signal and write it to the document in an `effect()`: ```ts import { Component, DOCUMENT, effect, inject, signal } from '@angular/core'; import { BsButton } from 'bootstrap-ng'; @Component({ selector: 'app-color-mode', imports: [BsButton], template: ` `, }) export class ColorMode { private readonly document = inject(DOCUMENT); protected readonly mode = signal<'light' | 'dark'>('light'); constructor() { effect(() => this.document.documentElement.setAttribute('data-bs-theme', this.mode())); } protected toggle(): void { this.mode.update((mode) => (mode === 'dark' ? 'light' : 'dark')); } } ``` If you save the choice, for example in `localStorage`, read it back before Angular starts. Otherwise a server-rendered or prerendered page paints in the system mode first and then flashes. A small inline script in `src/index.html` does this: ```html ``` The theme toggle on this site works this way. See [Server-side rendering](https://bootstrap-ng.com/getting-started/server-rendering/) for other code that should only run in the browser. ## Customize with Sass To change Bootstrap's design tokens at build time, import its Sass source in `src/styles.scss` instead of adding the compiled CSS to `angular.json`. Pass the tokens you want to change with `with ()`, and Bootstrap merges them with its defaults: ```scss @use 'bootstrap/scss/bootstrap' with ( $root-tokens: ( --spacer: 1.5rem, ), $alert-tokens: ( --alert-padding-x: 2rem, --alert-border-radius: 1rem, ) ); ``` The Angular CLI resolves `bootstrap/scss/bootstrap` from `node_modules`, so no extra configuration is needed. To add a theme color of your own, pass a `$theme-colors` map the same way. Bootstrap then generates a `.theme-` class, which you add to a component yourself because the `theme` input only accepts the built-in names: ```html ``` ## Customize with CSS variables Bootstrap outputs every token as a CSS variable with a `--bs-` prefix, so you can also change them in plain CSS, with no Sass build. Set them on a component's class to change every instance, or on one element: ```scss .alert { --bs-alert-padding-x: 2rem; --bs-alert-border-radius: 1rem; } ``` Bootstrap's own documentation lists every token: [Theme](https://getbootstrap.com/docs/6.0/customize/theme/), [Color modes](https://getbootstrap.com/docs/6.0/customize/color-modes/) and [Sass](https://getbootstrap.com/docs/6.0/customize/sass/). --- # Global configuration Source: Set default values for component inputs once, for the whole app or for part of it. ## Overview Each component with inputs that apps commonly set the same way everywhere, such as tooltip placement, the carousel interval or a translated label, has a `provideBs*Config()` function. Add it to your application's providers to change the defaults of every instance: ```ts import { ApplicationConfig } from '@angular/core'; import { provideBsDialogConfig, provideBsTableConfig, provideBsTooltipConfig } from 'bootstrap-ng'; export const appConfig: ApplicationConfig = { providers: [ provideBsDialogConfig({ backdrop: 'static' }), provideBsTableConfig({ hover: true, emptyText: 'Nothing here yet' }), provideBsTooltipConfig({ placement: 'bottom', delay: 300 }), ], }; ``` An input you set on a component always wins over the configuration, and options you leave out keep their built-in defaults. Components read their configuration when they are created, so set it before they render, not while the app is running. ## For part of an app The same functions work in a component's or a route's `providers`. Components in that part of the app use those defaults, merged over the app's own, so you only list what changes: ```ts import { Component } from '@angular/core'; import { BsTooltip, provideBsTooltipConfig } from 'bootstrap-ng'; @Component({ selector: 'app-toolbar', imports: [BsTooltip], // Tooltips in this toolbar open below it, with the app's delay. providers: [provideBsTooltipConfig({ placement: 'bottom' })], templateUrl: './toolbar.html', }) export class Toolbar {} ``` Popups that services create, such as dialogs from `BsDialogService` and toasts from `BsToaster`, use the app's configuration, and the options you pass when opening them win over it. The calendar that a datepicker opens also uses the app's calendar configuration. ## Calendars and datepickers Calendars and datepickers format dates in Angular's `LOCALE_ID` unless you give them a `locale`. Datepickers use the calendar configuration too, so one `provideBsCalendarConfig()` sets the locale, first day of the week and week numbers of both. Use `provideBsDatepickerConfig()` for datepicker-only options, or to set the shared ones differently for datepickers: ```ts import { ApplicationConfig } from '@angular/core'; import { provideBsCalendarConfig, provideBsDatepickerConfig } from 'bootstrap-ng'; export const appConfig: ApplicationConfig = { providers: [ // Every calendar and datepicker: weeks start on Sunday, with week numbers. provideBsCalendarConfig({ firstWeekday: 0, weekNumbers: true }), // Datepickers only: show the selected date as "March 5, 2026". provideBsDatepickerConfig({ dateFormat: { dateStyle: 'long' } }), ], }; ``` See [Internationalization](https://bootstrap-ng.com/getting-started/internationalization/) for locales and the labels to translate. ## Configuration functions Each function takes some of the inputs of its component, with the same names and types. Each configuration also has an interface, such as `BsAlertConfig`, and an injection token, such as `BS_ALERT_CONFIG`, for components of your own that want to read it. | Function | Inputs | | --- | --- | | [`provideBsAccordionConfig()`](https://bootstrap-ng.com/components/accordion/#api) | size, flush, exclusive | | [`provideBsAlertConfig()`](https://bootstrap-ng.com/components/alert/#api) | dismissible, closeLabel, animation | | [`provideBsBreadcrumbConfig()`](https://bootstrap-ng.com/components/breadcrumb/#api) | divider, label | | [`provideBsCarouselConfig()`](https://bootstrap-ng.com/components/carousel/#api) | autoplay, interval, pauseOnHover, ends, keyboard, and pauseLabel and playLabel on bsCarouselPlayPause | | [`provideBsCloseButtonConfig()`](https://bootstrap-ng.com/components/close-button/#api) | label (aria-label) | | [`provideBsDialogConfig()`](https://bootstrap-ng.com/components/dialog/#api) | backdrop, keyboard, animation | | [`provideBsDrawerConfig()`](https://bootstrap-ng.com/components/drawer/#api) | placement, scroll, sheet, backdrop, keyboard, animation | | [`provideBsMenuConfig()`](https://bootstrap-ng.com/components/menu/#api) | placement, strategy, autoClose, and hover on bsSubmenu | | [`provideBsNavOverflowConfig()`](https://bootstrap-ng.com/components/nav-overflow/#api) | moreText, moreLabel, iconPlacement, menuStrategy | | [`provideBsPaginationConfig()`](https://bootstrap-ng.com/components/pagination/#api) | maxPages, size, previousText, nextText, previousLabel, nextLabel | | [`provideBsPopoverConfig()`](https://bootstrap-ng.com/components/popover/#api) | placement, trigger, delay, animation | | [`provideBsProgressConfig()`](https://bootstrap-ng.com/components/progress/#api) | max, striped, animated | | [`provideBsScrollspyConfig()`](https://bootstrap-ng.com/components/scrollspy/#api) | topMargin, smoothScroll | | [`provideBsSpinnerConfig()`](https://bootstrap-ng.com/components/spinner/#api) | type, label | | [`provideBsTableConfig()`](https://bootstrap-ng.com/components/table/#api) | pageSize, stickyHeader, striped, hover, bordered, size, emptyText, loadingText, selectAllLabel, selectHeader, rowLabel, detailHeader, expandLabel, resizeLabel, sortAnnouncement | | [`provideBsToastConfig()`](https://bootstrap-ng.com/components/toasts/#api) | autohide, delay, animation, live, and closeLabel for BsToaster | | [`provideBsTooltipConfig()`](https://bootstrap-ng.com/components/tooltip/#api) | placement, trigger, delay, animation | | [`provideBsCalendarConfig()`](https://bootstrap-ng.com/forms/datepicker/#api) | firstWeekday, monthsCount, locale, prevLabel, nextLabel, hideOutsideDays, weekNumbers, weekNumbering, weekLabel, monthSelection, yearSelection, monthSelectionLabel, yearSelectionLabel, prevYearsLabel, nextYearsLabel, wareki | | [`provideBsChipInputConfig()`](https://bootstrap-ng.com/forms/chips/#api) | separator, allowDuplicates, createOnBlur, dismissible, removeLabel | | [`provideBsComboboxConfig()`](https://bootstrap-ng.com/forms/combobox/#api) | size, countText | | [`provideBsDatepickerConfig()`](https://bootstrap-ng.com/forms/datepicker/#api) | firstWeekday, monthsCount, weekNumbers, weekNumbering, wareki, locale, dateFormat, dateParser, invalidBehavior, placement, calendarLabel, size | | [`provideBsFileDropzoneConfig()`](https://bootstrap-ng.com/forms/file-dropzone/#api) | maxFileSize, fileList, thumbnails, size, removeLabel, fileListLabel, formatSize, rejectionText | | [`provideBsFormControlConfig()`](https://bootstrap-ng.com/forms/form-control/#api) | clearLabel | | [`provideBsStrengthConfig()`](https://bootstrap-ng.com/forms/password-strength/#api) | variant, minLength, weights, thresholds, messages, ariaLabel (aria-label) | | [`provideBsRangeConfig()`](https://bootstrap-ng.com/forms/range/#api) | bubble, formatter | | [`provideBsRatingConfig()`](https://bootstrap-ng.com/forms/rating/#api) | max, allowHalf, resettable, theme, size, valueText | | [`provideBsTypeaheadConfig()`](https://bootstrap-ng.com/forms/typeahead/#api) | minLength, debounce, placement, listLabel, resultsText, editable | Icons have their own setup: set the default icon library and add libraries with [`provideBsIcons()`](https://bootstrap-ng.com/getting-started/services/#icon-registry). --- # Services and helpers Source: The services, functions and types that bootstrap-ng exports besides its components. ## BsToaster Shows toasts from code, without a toast in your template. The toasts stack in a fixed `.toast-container` that is added to the page the first time a toast is shown. ```ts import { Component, inject } from '@angular/core'; import { BsButton, BsToaster } from 'bootstrap-ng'; @Component({ selector: 'app-save', imports: [BsButton], template: ``, }) export class Save { private readonly toaster = inject(BsToaster); protected save(): void { this.toaster.show({ title: 'Saved', body: 'Your changes were saved.' }); } } ``` | Name | Type | Description | | --- | --- | --- | | `show(options)` | `BsToastRef` | Shows a toast and returns a reference with hide() and afterHidden. | | `clear()` | `void` | Hides every toast. | | `setPlacement(placement)` | `void` | Where the toasts stack on the screen. Defaults to 'bottom-end'. | See [Toasts](https://bootstrap-ng.com/components/toasts/#service) for every option, themes and templates with actions. ## BsLiveAnnouncer Reads a message out to screen reader users through visually hidden live regions that stay on the page. Use it for changes that happen without moving focus, such as search results updating. Toasts and the carousel already announce through it. ```ts import { Component, inject, signal } from '@angular/core'; import { BsLiveAnnouncer } from 'bootstrap-ng'; @Component({ … }) export class Search { private readonly announcer = inject(BsLiveAnnouncer); protected readonly results = signal([]); protected search(query: string): void { // … this.announcer.announce(`${this.results().length} results found`); } } ``` | Name | Type | Description | | --- | --- | --- | | `announce(message, politeness?)` | `void` | Reads the message out. Politeness is 'polite' (the default) or 'assertive', which interrupts the screen reader and is meant for errors. | | `clear()` | `void` | Clears pending and current announcements. | See [Accessibility](https://bootstrap-ng.com/getting-started/accessibility/#announcements) for why a region that stays on the page is announced more reliably than one added with its text. ## BsIconRegistry The icon libraries that `bs-icon` loads from, and a cache of the icons it has loaded. `bootstrap` (the default), `font-awesome`, `material`, `modus` and `phosphor` are built in and load from jsDelivr. Set the default library and add your own with `provideBsIcons()`, self-host a built-in set by passing a `baseUrl` to its factory, such as `bootstrapIcons()`, `fontAwesomeIcons()`, `materialSymbols()`, `modusIcons()` or `phosphorIcons()`, or bundle icons as SVG markup in a library’s `icons`. Bundled icons need no request and render on the server; each factory takes `icons` too, which are used before its files. ```ts import { ApplicationConfig } from '@angular/core'; import { bootstrapIcons, provideBsIcons } from 'bootstrap-ng'; // Bundled into your app as text, so it shows without a request. import logo from './logo.svg' with { loader: 'text' }; export const appConfig: ApplicationConfig = { providers: [ provideBsIcons({ // Icons without a library come from Font Awesome. defaultLibrary: 'font-awesome', libraries: { // Serve Bootstrap Icons from your own site (see the assets entry below). bootstrap: bootstrapIcons({ baseUrl: '/icons/bootstrap' }), // Any icon set with an SVG file per icon. lucide: { resolver: (name) => `https://cdn.jsdelivr.net/npm/lucide-static@1.48.0/icons/${name}.svg`, }, // Icons bundled as SVG markup: . app: { icons: { logo } }, }, }), ], }; ``` To self-host, install the icon set’s npm package and copy its SVG files into your build with an `assets` entry in `angular.json`, then pass the output path as `baseUrl`. Use the package folder that holds the set’s variant folders: `bootstrap-icons/icons`, `@fortawesome/fontawesome-free/svgs`, `@material-symbols/svg-400`, `@trimble-oss/modus-icons/dist` or `@phosphor-icons/core/assets`, with `**/*.svg` as the glob for sets that have variants. ```json "assets": [ { "glob": "**/*", "input": "public" }, { "glob": "*.svg", "input": "node_modules/bootstrap-icons/icons", "output": "icons/bootstrap" } ] ``` To import an SVG file as text, as `logo.svg` above, declare its type once in your app. ```ts // src/svg.d.ts: types for importing SVG files as text. declare module '*.svg' { const content: string; export default content; } ``` | Name | Type | Description | | --- | --- | --- | | `register(name, library)` | `void` | Adds an icon library, or replaces the one with the same name. | | `addIcons(library, icons)` | `void` | Adds icons, as SVG markup by name, to a library, creating it when it does not exist. They show without a request and render on the server. | | `get(name)` | `BsIconLibrary \| undefined` | Returns the library registered under the name. | | `load(url)` | `Promise` | Fetches an SVG once, removes scripts and event handlers, and returns a copy. | | `parse(markup)` | `SVGSVGElement` | Parses SVG markup, cleaned like a loaded SVG, and returns a copy. Throws when it is not an SVG. | | `defaultLibrary` | `WritableSignal` | Name of the library that icons without a library use. | See [Icon](https://bootstrap-ng.com/components/icon/) for every built-in library and its variants. ## Helper functions bootstrap-ng uses these internally. They are exported for components that you build on top of it. | Name | Type | Description | | --- | --- | --- | | `themeClass(theme)` | `string` | Returns the .theme-* class for a BsTheme, such as 'theme-danger', or an empty string when the theme is null. | | `waitForTransition(element)` | `Promise` | Resolves when the element's CSS transition ends, at once when it has none, and after a fallback timer if transitionend never fires. | | `getTransitionDuration(element)` | `number` | The element's first transition duration plus delay, in milliseconds. | | `uniqueId(prefix)` | `string` | Returns an id that is unique on the page, such as 'bs-collapse-3'. | For example, to emit an event after a fade-out finishes, as bootstrap-ng's own `hidden` and `closed` outputs do: ```ts protected async close(): Promise { this.element.classList.remove('show'); await waitForTransition(this.element); this.closed.emit(); } ``` ## Types | Name | Type | Description | | --- | --- | --- | | `BsTheme` | `string union` | 'primary' \| 'accent' \| 'success' \| 'danger' \| 'warning' \| 'info' \| 'inverse' \| 'secondary' | | `BsPlacement` | `string union` | Where a tooltip, popover or menu opens: 'top', 'bottom', 'left', 'right', 'start' or 'end', optionally followed by '-start' or '-end'. | ## BOOTSTRAP_NG An array of every component and directive, to add to a component's `imports` while prototyping. Import single components in production code so unused ones are removed from your bundle. See [Conventions](https://bootstrap-ng.com/getting-started/conventions/#imports). --- # Server-side rendering Source: Use bootstrap-ng with server-side rendering, prerendering, hydration and zoneless change detection. ## Server-side rendering and prerendering bootstrap-ng works with Angular's server-side rendering and build-time prerendering. Add them to an application with the Angular CLI: ```sh ng add @angular/ssr ``` Components render Bootstrap's markup, classes and ARIA attributes on the server, so the page is styled and readable before JavaScript loads. Work that needs a browser, such as measuring elements, positioning popups, opening a ``, moving focus or starting a carousel, runs in `afterNextRender()` or `afterRenderEffect()`, which Angular skips on the server. So anything that needs the browser, such as a modal dialog's backdrop and focus trap, starts once the page hydrates. ## Hydration bootstrap-ng supports full hydration and needs no `ngSkipHydration`. Enable it with event replay, so that clicks made before the page hydrates are not lost: ```ts import { ApplicationConfig } from '@angular/core'; import { provideClientHydration, withEventReplay } from '@angular/platform-browser'; export const appConfig: ApplicationConfig = { providers: [provideClientHydration(withEventReplay())], }; ``` This site prerenders every page and hydrates it with this configuration, so each component page is a working example. ## Browser-only code in your application `BsToaster` and `BsLiveAnnouncer` add elements to the document body. Call them from event handlers, or wrap calls that run on load in `afterNextRender()`, so they don't run on the server: ```ts import { afterNextRender, Component, inject } from '@angular/core'; import { BsToaster } from 'bootstrap-ng'; @Component({ … }) export class Welcome { private readonly toaster = inject(BsToaster); constructor() { // Runs in the browser only, after the first render. afterNextRender(() => { this.toaster.show({ body: 'Welcome back!' }); }); } } ``` The same applies to your own use of `localStorage`, `matchMedia` or `window`, for example when you save the color mode. See [Switching modes](https://bootstrap-ng.com/getting-started/theming/#switching) for how to apply a saved mode before a prerendered page paints. ## Zoneless change detection bootstrap-ng does not need `zone.js`. Components keep their state in signals, so they update with zoneless change detection, which is the default for new Angular applications. The library's tests and this site run without `zone.js`. Applications that still use `zone.js` work as well. --- # Content Security Policy Source: Run bootstrap-ng under a strict Content Security Policy (CSP), with nonces for Angular's styles and no `'unsafe-eval'`. ## What bootstrap-ng needs bootstrap-ng doesn't use `eval()`, inline scripts or Bootstrap's JavaScript, so it adds nothing to `script-src`. Its needs are about styles and the files it loads: - A few components, such as `bs-icon`, data tables and the clear button of `clearable` form controls, have component styles. Angular adds them in `