简体   繁体   中英

Passing default date range to ng bootstrap dateRangePicker

I'm trying to pass the default date range to ng bootstrap date range picker. Input field doesn't get updated.

  ngOnInit() {
    this.startDate = {year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate()};
    this.maxDate = { year: now.getFullYear() + 1, month: now.getMonth() + 1, day: now.getDate()};
    this.minDate = {year: now.getFullYear() - 1, month: now.getMonth() + 1, day: now.getDate()};
    let parsed = ' '
    this.fromDate = this.ngbCalendar.getToday();
    this.toDate = this.ngbCalendar.getNext(this.ngbCalendar.getToday(), 'd', 10);
    if(this.fromDate) {
      parsed += this._parserFormatter.format(this.fromDate);
    }
    if(this.toDate) {
      parsed += ' - ' + this._parserFormatter.format(this.toDate);
    }
    //passing default date
    this.model = parsed;
    this.renderer.setProperty(this.myRangeInput.nativeElement, 'value', parsed);
   }

Demo

从 html 中删除[(ngModel)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM