Skip to main content

DHTMLX Booking. Angular integration example

Demo of DHTMLX Booking integration with Angular using the official GitHub demo. Shows the component wrapper, the container reference, and cleanup on destroy. For a step-by-step setup, see the detailed Angular integration guide.

Try it online

View on GitHub - open the repository and click "Open in Codespaces" on the README page to launch a configured Angular app with DHTMLX Booking. No local setup required.

Angular wraps the widget in one component and sets encapsulation: ViewEncapsulation.None. The template holds the container element. @ViewChild("container", { static: true }) resolves that element before ngOnInit, and nativeElement is what the constructor mounts into. Booking works with a DOM node rather than with a framework template.

Styles stay in booking.component.css. That file imports @dhx/trial-booking/dist/booking.css and sets html, body, and .widget to height: 100%. Turning encapsulation off lets those rules apply to the page.

The instance is created in ngOnInit and kept on a private field, which is what lets the rest of the component call methods on it later. The Angular guide attaches handlers in that same method, for example this._booking.api.on("select-slot", obj => ...). ngOnDestroy calls destructor() when Angular removes the component.

Solution overview​

To run DHTMLX Booking inside an Angular application:

  1. Import the package and the styles - import { Booking } from "@dhx/trial-booking". In booking.component.css, import @dhx/trial-booking/dist/booking.css, set html, body, and .widget to height: 100%, and set encapsulation: ViewEncapsulation.None on the component.
  2. Declare the container as <div #container class="widget"></div> and reference it with @ViewChild("container", { static: true }).
  3. Create the widget in ngOnInit - load the cards with getData() and call new Booking(this.booking_container.nativeElement, { data }).
  4. Keep the instance on a field such as private _booking, so later calls have something to talk to.
  5. Subscribe where you create it - the guide uses this._booking.api.on("select-slot", obj => ...) to report the picked slot.
  6. Destroy it in ngOnDestroy with this._booking.destructor() when Angular removes the component.

API reference​

Additional resources​