For angular 2, you can use this directive
import {Directive, ElementRef, HostListener} from '@angular/core'; @Directive({ selector: '[appDateClick]' }) export class DateClickDirective { @HostListener('focus') onMouseFocus() { this.el.nativeElement.type = 'date'; setTimeout(()=>{this.el.nativeElement.click()},2); } @HostListener('blur') onMouseBlur() { if(this.el.nativeElement.value == ""){ this.el.nativeElement.type = 'text'; } } constructor(private el:ElementRef) { } }
and use it as shown below.
<input appDateClick name="targetDate" placeholder="buton name" type="text">
Dhafer.Dhib Oct 27 '17 at 11:46 on 2017-10-27 11:46
source share