Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何告诉ng2 eonasdan datetimepicker元素显示日历?_Angular_Datetimepicker - Fatal编程技术网

Angular 如何告诉ng2 eonasdan datetimepicker元素显示日历?

Angular 如何告诉ng2 eonasdan datetimepicker元素显示日历?,angular,datetimepicker,Angular,Datetimepicker,我正在使用“ng2 eonasdan datetimepicker”中的datetimepicker,它工作得很好。但是我有另一个控件,我希望在单击另一个控件时打开日历 我试过几种方法,最新的是: export class Item { @ViewChild('datetimepicker') datetimepickerElement: ElementRef; ... public showDate() { let event = new MouseEvent('

我正在使用“ng2 eonasdan datetimepicker”中的datetimepicker,它工作得很好。但是我有另一个控件,我希望在单击另一个控件时打开日历

我试过几种方法,最新的是:

export class Item {
   @ViewChild('datetimepicker') datetimepickerElement: ElementRef;

   ...

   public showDate() {
    let event = new MouseEvent('click', {bubbles: true});
    this.datetimepickerElement.nativeElement.dispatchEvent(event);
   }

   public getDueDate(): moment {
     return ...
   }

}
其中,相关html片段为:

     <input #datetimepicker
         type='text'
         class="form-control"
         a2e-datetimepicker
         [date]="getDueDate()"
         [options]="datetimepicker_options"
         style="opacity: 0; maxlength: 4; height: 30px; width: 100px;"
         (onChange)="dateToChange($event)"
         />

但这不会打开a2e日期时间选择器的关联日历

我在尝试直接访问a2e datetimepicker时到处寻找,但没有成功。你知道怎么做吗?或者为什么dispatchEvent甚至nativeElement.click()无法到达a2e日期时间选择器


谢谢

事实证明,我在这里需要的是调用focus()。像这样:

public showDate() {
   this.datetimepickerElement.nativeElement.focus();
}
我还学习了如何像这样访问底层指令:

  import { DateTimePickerDirective } from '../../../../../node_modules/ng2-eonasdan-datetimepicker/dist/datetimepicker.directive';

  @ViewChild(DateTimePickerDirective) datetimempickerDirective;
然后我们可以做:

    this.datetimempickerDirective.dpElement[0].focus();
但在这种情况下,这也会让事情变得更容易

   this.datetimepickerElement.nativeElement.focus();

这将有望帮助一些仍在学习angular2的人。

事实证明,我在这里需要的是调用focus()。像这样:

public showDate() {
   this.datetimepickerElement.nativeElement.focus();
}
我还学习了如何像这样访问底层指令:

  import { DateTimePickerDirective } from '../../../../../node_modules/ng2-eonasdan-datetimepicker/dist/datetimepicker.directive';

  @ViewChild(DateTimePickerDirective) datetimempickerDirective;
然后我们可以做:

    this.datetimempickerDirective.dpElement[0].focus();
但在这种情况下,这也会让事情变得更容易

   this.datetimepickerElement.nativeElement.focus();
这将有助于一些仍在学习angular2的人