Skip to content

Commit

Permalink
fix(tooltip): remove tooltips when element destroyed with event='hove…
Browse files Browse the repository at this point in the history
…r' (#33)
  • Loading branch information
doug-a-brunner authored and madoBaker committed Sep 21, 2018
1 parent 2fcc655 commit 310d968
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/tooltip.directive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
AfterViewInit,
ApplicationRef,
ComponentFactoryResolver,
ComponentRef,
Directive,
ElementRef,
HostListener,
Input,
ViewContainerRef
Directive, ElementRef, Input, ApplicationRef, ComponentFactoryResolver,
ViewContainerRef, ComponentRef, HostListener, OnDestroy
} from '@angular/core';
import { Platform } from 'ionic-angular';

Expand All @@ -16,7 +9,8 @@ import { TooltipBox } from './tooltip-box.component';
@Directive({
selector: '[tooltip]'
})
export class Tooltip {
export class Tooltip implements OnDestroy {


@Input() tooltip: string;

Expand Down Expand Up @@ -67,6 +61,19 @@ export class Tooltip {
private _componentFactoryResolver: ComponentFactoryResolver
) {}

/**
* Show the tooltip immediately after initiating view if set to
*/
ngAfterViewInit() {
if (this._active) {
this.trigger();
}
}

ngOnDestroy() {
if (this.tooltipElement && typeof this.tooltipElement.destroy === 'function') this.tooltipElement.destroy();
}

/**
* Set the canShow property
* Ensure that tooltip is shown only if the tooltip string is not falsey
Expand Down

0 comments on commit 310d968

Please sign in to comment.