【问题标题】:Angular2 & ngbootstrap Datepicker and the NavigateTo() functionAngular2 & ngbootstrap Datepicker 和 NavigateTo() 函数
【发布时间】:2017-09-25 16:31:58
【问题描述】:

在这个 plnkr(由 bootstrap 提供)中,他们使用一个按钮来调用 navigateTo() 函数。这会将日历中的焦点重置为当前月份或他们选择的月份,具体取决于他们是否发送年份和月份。

http://embed.plnkr.co/wC4XeI8OOIBAMLo9yeFc/

如何在我的 .ts 文件中以编程方式执行此操作?

myapp.ts
dp: NgbDatepicker;
model: NgbDateStruct;

onClick() // from a button for temporary testing
{
  this.dp.navigateTo (); // Cannot read property 'navigateTo' of undefined
  this.model = {year: 2017, month: 10, day: 3}; // this selects the date properly
}

当我输入 this.dp.navigateTo 时,vsCode 有正确的代码提示,但它不起作用。有任何想法吗?谢谢。

【问题讨论】:

  • 可以分享模板html代码吗?
  • 已解决:需要添加@Viewchild('dp') dp: any;然后我可以使用 this.dp.navigateTo();
  • 模板代码和bootstrap中的plnkr一样

标签: angular ng-bootstrap


【解决方案1】:

您可以在 @ViewChild 装饰器的帮助下完成此操作

@ViewChild( 'dp') dp;
this.dp.navigateTo({year: 2018, month: 2});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多