Skip to content

Commit

Permalink
refactor(): use HostListener instead of host property
Browse files Browse the repository at this point in the history
Comply with Angular Style Guide 06-03
  • Loading branch information
ihadeed committed Sep 11, 2017
1 parent 0444862 commit ce4d1d8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/tooltip.directive.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
Directive, ElementRef, Input, ApplicationRef, ComponentFactoryResolver,
ViewContainerRef, ComponentRef, AfterViewInit
ViewContainerRef, ComponentRef, AfterViewInit, HostListener
} from '@angular/core';
import { Platform } from 'ionic-angular';
import { TooltipBox } from './tooltip-box.component';

@Directive({
selector: '[tooltip]',
host: {
'(press)': 'event === "press" && trigger()',
'(click)': 'event === "click" && trigger()',
'(mouseenter)': 'event === "hover" && active = true',
'(mouseleave)': 'event === "hover" && active = false'
}
selector: '[tooltip]'
})
export class Tooltip implements AfterViewInit {

Expand Down Expand Up @@ -142,6 +136,26 @@ export class Tooltip implements AfterViewInit {

}

@HostListener('click')
onClick(): void {
if (this.event === 'click') this.trigger();
}

@HostListener('press')
onPress(): void {
if (this.event === 'press') this.trigger();
}

@HostListener('mouseenter')
onMouseEnter(): void {
if (this.event === 'hover') this.active = true;
}

@HostListener('mouseleave')
onMouseLeave(): void {
if (this.event === 'hover') this.active = false;
}

private _createTooltipComponent() {
let
viewport: ViewContainerRef = (<any>this.appRef.components[0])._component._viewport,
Expand Down

0 comments on commit ce4d1d8

Please sign in to comment.