Skip to content

Commit

Permalink
fix(popover): properly re-position popovers
Browse files Browse the repository at this point in the history
Closes #710
  • Loading branch information
pkozlowski-opensource committed Sep 12, 2016
1 parent 2f59666 commit a729ba9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Input,
ChangeDetectionStrategy,
OnInit,
AfterViewChecked,
OnDestroy,
Injector,
Renderer,
Expand All @@ -13,6 +12,7 @@ import {
TemplateRef,
ViewContainerRef,
ComponentFactoryResolver,
NgZone
} from '@angular/core';

import {listenToTriggers} from '../util/triggers';
Expand All @@ -38,7 +38,7 @@ export class NgbPopoverWindow {
* A lightweight, extensible directive for fancy popover creation.
*/
@Directive({selector: '[ngbPopover]', exportAs: 'ngbPopover'})
export class NgbPopover implements OnInit, AfterViewChecked, OnDestroy {
export class NgbPopover implements OnInit, OnDestroy {
/**
* Content to be displayed as popover.
*/
Expand All @@ -59,15 +59,22 @@ export class NgbPopover implements OnInit, AfterViewChecked, OnDestroy {
private _popupService: PopupService<NgbPopoverWindow>;
private _windowRef: ComponentRef<NgbPopoverWindow>;
private _unregisterListenersFn;
private _zoneSubscription: any;

constructor(
private _elementRef: ElementRef, private _renderer: Renderer, injector: Injector,
componentFactoryResolver: ComponentFactoryResolver, viewContainerRef: ViewContainerRef,
config: NgbPopoverConfig) {
componentFactoryResolver: ComponentFactoryResolver, viewContainerRef: ViewContainerRef, config: NgbPopoverConfig,
ngZone: NgZone) {
this.placement = config.placement;
this.triggers = config.triggers;
this._popupService = new PopupService<NgbPopoverWindow>(
NgbPopoverWindow, injector, viewContainerRef, _renderer, componentFactoryResolver);

this._zoneSubscription = ngZone.onStable.subscribe(() => {
if (this._windowRef) {
positionElements(this._elementRef.nativeElement, this._windowRef.location.nativeElement, this.placement);
}
});
}


Expand Down Expand Up @@ -107,13 +114,10 @@ export class NgbPopover implements OnInit, AfterViewChecked, OnDestroy {
this.toggle.bind(this));
}

ngAfterViewChecked() {
if (this._windowRef) {
positionElements(this._elementRef.nativeElement, this._windowRef.location.nativeElement, this.placement, false);
}
ngOnDestroy() {
this._unregisterListenersFn();
this._zoneSubscription.unsubscribe();
}

ngOnDestroy() { this._unregisterListenersFn(); }
}

export const NGB_POPOVER_DIRECTIVES = [NgbPopover, NgbPopoverWindow];

0 comments on commit a729ba9

Please sign in to comment.