title: Angular Material, Md-datepicker - open date-picker on input click
body: <p>I want to open calendar where user chooses date from date-picker not only when user clicks on calendar icon, but also when clicks on input field. <a href="https://material.angular.io/components/datepicker/overview" rel="noreferrer">Material DatePicker</a>. So I create directive for this, attaching it to <code>&lt;md-datepicker&gt;</code> and also watching for <code>(click)</code> event on input:</p>
  
  <p>Html:</p>
  
  <pre><code>  &lt;md-form-field class="field-half-width"&gt;
      &lt;input mdInput [mdDatepicker]="picker2" placeholder="Galioja iki"
              formControlName="dateUntil" (click)="clickInp()"&gt;
      &lt;md-datepicker-toggle  id="calendar" mdSuffix [for]="picker2" &gt;&lt;/md-datepicker-toggle&gt;
      &lt;md-datepicker #picker2 manualClickRenderer&gt;&lt;/md-datepicker&gt;
    &lt;/md-form-field&gt; 
  </code></pre>
  
  <p>form-component:</p>
  
  <pre><code>import {ManualClickRerender} from '../shared/directives/manual-click.directive';
  
  @Component({
    selector: 'form',
    providers: [ManualClickRerender]
  })
  
  export class FormComponent implements OnInit, OnChanges {
   ...
    clickInp() {
      this.manualClickRerender.botClick();
    }
  </code></pre>
  
  <p>Directive:</p>
  
  <pre><code>import { Directive, Renderer, ElementRef } from '@angular/core';
  @Directive({
    selector: '[manualClickRenderer]'
  })
  export class ManualClickRerender {
  
    private nativeElement : Node;
  
    constructor( private renderer : Renderer, private element : ElementRef ) {
      this.nativeElement = element.nativeElement;
    }
  
    botClick() {    
      console.log(this.nativeElement); // logs the whole form, not the &lt;md-datepicker&gt;. I guess problem is here
      this.renderer.invokeElementMethod(this.nativeElement, 'click', []);
    }
  }
  </code></pre>
  
  <p>This is my first custom directive ever, so not completaly sure how to import / provide it, etc. I imported it in main module and added to declarations, but after I imported it in my form component (I did that because need to pass click event to it) got error that there are no providers to ManualClickRerender. So added it as provider as well in form-component. So, yes, I imported it twice.. </p>
  
  <p>Also as you see, I use Rerender, not Rerender2, because it doesn't have <code>invokeElementMethod</code> method... But I bet there is a workaround, just dont know it.. </p>
  
  <p>Thanks in advance for any info.</p>