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.
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:
- Import the package and the styles -
import { Booking } from "@dhx/trial-booking". Inbooking.component.css, import@dhx/trial-booking/dist/booking.css, sethtml,body, and.widgettoheight: 100%, and setencapsulation: ViewEncapsulation.Noneon the component. - Declare the container as
<div #container class="widget"></div>and reference it with@ViewChild("container", { static: true }). - Create the widget in
ngOnInit- load the cards withgetData()and callnew Booking(this.booking_container.nativeElement, { data }). - Keep the instance on a field such as
private _booking, so later calls have something to talk to. - Subscribe where you create it - the guide uses
this._booking.api.on("select-slot", obj => ...)to report the picked slot. - Destroy it in
ngOnDestroywiththis._booking.destructor()when Angular removes the component.
API reference
- Integration with Angular: Component, module, and bootstrap setup
- data: The card and slot format passed at initialization
- setConfig(): Replacing the records after the widget is created
- Properties overview: Every configuration property
Related examples
- React integration: the widget inside a React component
- Svelte integration: the widget inside a Svelte component
- Backend integration: load records and save reservations from a service