Skip to content

Commit

Permalink
fix(datepicker): access view child from ngAfterViewInit (#3152)
Browse files Browse the repository at this point in the history
Datepicker accessed a view child from the `ngAfterContentInit` hook instead of accessing it from the `ngAfterViewInit` hook.

This doesn't work anymore with Ivy. That is a regression in Ivy, but is also an issue with ng-bootstrap which doesn't respect the standard life-cycle.
Besides, the component didn't implement the `AfterContentInit` interface.
It now implements the `AfterViewInit` interface.

Fixes #3150
  • Loading branch information
jnizet authored and maxokorokov committed Apr 30, 2019
1 parent 5a4f4b8 commit 0e54eef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/datepicker/datepicker.ts
@@ -1,6 +1,7 @@
import {fromEvent, merge, Subject} from 'rxjs';
import {filter, take, takeUntil} from 'rxjs/operators';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Expand Down Expand Up @@ -119,7 +120,7 @@ export interface NgbDatepickerNavigateEvent {
providers: [NGB_DATEPICKER_VALUE_ACCESSOR, NgbDatepickerService, NgbDatepickerKeyMapService]
})
export class NgbDatepicker implements OnDestroy,
OnChanges, OnInit, ControlValueAccessor {
OnChanges, OnInit, AfterViewInit, ControlValueAccessor {
model: DatepickerViewModel;

@ViewChild('months') private _monthsEl: ElementRef<HTMLElement>;
Expand Down Expand Up @@ -319,7 +320,7 @@ export class NgbDatepicker implements OnDestroy,
this._service.open(NgbDate.from(date ? date.day ? date as NgbDateStruct : {...date, day: 1} : null));
}

ngAfterContentInit() {
ngAfterViewInit() {
this._ngZone.runOutsideAngular(() => {
const focusIns$ = fromEvent<FocusEvent>(this._monthsEl.nativeElement, 'focusin');
const focusOuts$ = fromEvent<FocusEvent>(this._monthsEl.nativeElement, 'focusout');
Expand Down

0 comments on commit 0e54eef

Please sign in to comment.