Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. @Directive({ selector: '[my-tooltip]' })
  2. export class TooltipDirective implements OnDestroy {
  3.  
  4. @Input() tooltipTitle: string = '';
  5. private id: string;
  6.  
  7. constructor(private tooltipService: TooltipService) { }
  8.  
  9. @HostListener('mouseenter')
  10. onMouseEnter(): void {
  11. this.id = Math.random();
  12. this.tooltipService.push({ id: this.id, title: this.tooltipTitle });
  13. }
  14.  
  15. @HostListener('mouseleave')
  16. onMouseLeave(): void {
  17. this.destroy();
  18. }
  19.  
  20. ngOnDestroy(): void {
  21. this.destroy();
  22. }
  23.  
  24. destroy(): void {
  25. const idx = this.tooltipService.findIndex((t) => {
  26. return t.id === this.id;
  27. });
  28.  
  29. this.tooltipService.splice(idx, 1);
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement