【发布时间】: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