Date Range Picker Integrations

Angular

Read the input with ViewChild after the view initializes. The standalone component removes its picker when Angular destroys the view.

App source

report-dates.ts
import {
  AfterViewInit, Component, ElementRef, OnDestroy, ViewChild
} from '@angular/core';
import DateRangePicker from 'daterangepicker';
import 'daterangepicker/daterangepicker.css';

@Component({
  selector: 'report-dates',
  standalone: true,
  template: '<label>Report dates<input #dates type="text"></label>'
})
export class ReportDates implements AfterViewInit, OnDestroy {
  @ViewChild('dates', { static: true }) input!: ElementRef<HTMLInputElement>;
  private picker?: DateRangePicker;

  ngAfterViewInit() {
    this.picker = new DateRangePicker(this.input.nativeElement, { singleCalendar: true });
  }

  ngOnDestroy() {
    this.picker?.remove();
  }
}
main.ts
import '@angular/compiler';
import { provideZonelessChangeDetection } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { ReportDates } from './report-dates';

bootstrapApplication(ReportDates, {
  providers: [provideZonelessChangeDetection()]
}).catch(console.error);
index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Report dates</title>
  <link rel="stylesheet" href="../../daterangepicker.css">
  <script type="module" src="../assets/angular.js"></script>
</head>
<body>
  <report-dates></report-dates>
</body>
</html>
Run this example locally

Serve the website directory over HTTP and open /examples/angular/. To edit the app, change its files in example/integrations/angular and run these commands from example/integrations.

npm ci
npm run build