ngx-bootstrap Documentation

repository·development·Indexed 26 days ago

https://github.com/valor-software/ngx-bootstrap

A library providing Bootstrap components for Angular applications, enabling Bootstrap's UI capabilities without the original Bootstrap JavaScript. Version 21.2.1 requires Angular's zoneless change detection and utilizes signal-based inputs and output functions. The library includes components such as Accordion and Alerts, and provides a compatibility matrix for Angular and Bootstrap CSS versions.

Tokens
37.7K
Snippets
62
Records
357
Agent score
90%

What's inside ngx-bootstrap

  1. Use the animation option with the Modals service

    development
    When using the BsModalService to open modals, you can control whether the modal includes animation effects. This is typically managed by passing configuration options to the service. In the context of ngx-bootstrap, this allows users to toggle between animated and non-animated modal popups, which can be useful for performance-sensitive environments or specific UI requirements.
  2. Handle Modal lifecycle events with the Modals service

    development

    When using the BsModalService to open modals, you can subscribe to lifecycle events to execute logic when the modal's visibility state changes. The following events are available:

    • onShow: Fired when the modal begins to show.
    • onShown: Fired when the modal has been fully shown (animations completed).
    • onHide: Fired when the modal begins to hide.
    • onHidden: Fired when the modal has been fully hidden (animations completed).

    These events are triggered regardless of how the modal is closed, including via the close button, clicking the backdrop, or pressing the ESC key.

  3. Implement Datepicker that closes on outside click

    development

    In ngx-bootstrap, the datepicker component can be configured to either close when a user clicks outside the datepicker container or remain open. This behavior is typically controlled by the internal implementation of the datepicker container and its interaction with the document click events.

    To achieve a datepicker that closes when clicking outside, ensure the component is used in a way that allows the bs-datepicker-container to detect clicks outside its scope. When a user clicks outside the active container, the container should disappear.

  4. Use Typeahead with NgModules

    development

    To use the Typeahead component in a traditional Angular module-based application, import TypeaheadModule and BrowserAnimationsModule into your @NgModule imports array.

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
    
    @NgModule({
      imports: [
        BrowserAnimationsModule,
        TypeaheadModule,
        ...
      ],
      // ...
    })
    export class AppModule {}
  5. Subscribe to Datepicker visibility events

    development

    You can monitor when the bs-datepicker-container is opened or closed by subscribing to the visibility events provided by the ngx-bootstrap Datepicker.

    • onShown: Fired when the datepicker container becomes visible (e.g., when the user clicks the input).
    • onHidden: Fired when the datepicker container is closed (e.g., after a date is selected or the user clicks away).
  6. Explore Datepicker use-cases

    development
    The Datepicker component offers extensive features including inline mode, initial state management, custom date formats, and hiding on scroll. It supports various themes, locales, min/max date constraints, and disabling specific days. Integration with Forms and Reactive Forms is supported. Other features include manual triggering, placement options, visibility events, value change events, selecting dates from other months, week selection, handling outside clicks, and custom triggers.
  7. Implement a dynamic Timepicker with ngx-bootstrap

    development

    To create a dynamic timepicker component, you can programmatically control the hour, minute, and AM/PM state. In a dynamic implementation, clicking external buttons can update the component's inputs to specific values (e.g., setting the time to 14:00) or clear the inputs to show placeholders (e.g., 'HH' and 'MM') and reset the period to 'AM'.

    Key behaviors for a dynamic timepicker include:

    • Setting values: Updating the hour and minute inputs and toggling the AM/PM button.
    • Clearing values: Resetting inputs to placeholders and defaulting the period to 'AM'.
    • Validation: Displaying alerts for valid time formats or invalid inputs.