import { Directive, Input, OnInit, ElementRef, Injector, AfterViewInit } from '@angular/core'; @Directive({ selector: '[show-title]' }) export class ShowTitleDirective implements OnInit, AfterViewInit { @Input('show-title') enableTips; constructor(private el: ElementRef, private injector: Injector) {} ngOnInit() { } ngAfterViewInit() { if (this.enableTips) { this.el.nativeElement.title = this.el.nativeElement.innerText; } } }