From 36918b594270959d36637671b6494670e17629c4 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Fri, 4 Oct 2019 15:57:36 +0100 Subject: [PATCH] refactor(datepicker): move - @@ -29,7 +38,7 @@ import {NgbDatepickerI18n} from './datepicker-i18n'; ` }) -export class NgbDatepickerNavigationSelect { +export class NgbDatepickerNavigationSelect implements AfterViewChecked { @Input() date: NgbDate; @Input() disabled: boolean; @Input() months: number[]; @@ -37,9 +46,28 @@ export class NgbDatepickerNavigationSelect { @Output() select = new EventEmitter(); - constructor(public i18n: NgbDatepickerI18n) {} + @ViewChild('month', {static: true, read: ElementRef}) monthSelect: ElementRef; + @ViewChild('year', {static: true, read: ElementRef}) yearSelect: ElementRef; + + private _month = -1; + private _year = -1; + + constructor(public i18n: NgbDatepickerI18n, private _renderer: Renderer2) {} changeMonth(month: string) { this.select.emit(new NgbDate(this.date.year, toInteger(month), 1)); } changeYear(year: string) { this.select.emit(new NgbDate(toInteger(year), this.date.month, 1)); } + + ngAfterViewChecked() { + if (this.date) { + if (this.date.month !== this._month) { + this._month = this.date.month; + this._renderer.setProperty(this.monthSelect.nativeElement, 'value', this._month); + } + if (this.date.year !== this._year) { + this._year = this.date.year; + this._renderer.setProperty(this.yearSelect.nativeElement, 'value', this._year); + } + } + } }