Angular 2 ngb-datepicker navigationTo [英] Angular 2 ngb-datepicker navigateTo

查看:41
本文介绍了Angular 2 ngb-datepicker navigationTo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用ngb-datepicker.当我在组件类中执行函数时,我想导航到特定的月份/年份.我知道ngbDatePicker中有一个名为navigationTo的方法,可以调用该方法导航到特定的月/年.但这是在HTML页面中完成的,如下所示.我可以在组件类中调用相同的方法NavigationTo吗?谢谢.

I am using ngb-datepicker in my application. I want to navigate to a particular month/year when a function is executed in my component class. I know there is method in ngbDatePicker called navigateTo that can called to navigate to particular month/year. But this is done in HTML page as below. Can I call the same method navigateTo in component class? Thank you.

<ngb-datepicker #dp [(ngModel)]="model" (navigate)="date = 
$event.next"></ngb-datepicker>
<button class="btn btn-sm btn-outline-primary mr-2" 
(click)="dp.navigateTo()">To current month</button>

推荐答案

您可以在component.ts中轻松实现

you can do it easily in component.ts

 @ViewChild('dp') datepicker: NgbDatepicker;

然后,

    ngAfterViewInit() {
    this.datepicker.navigateTo(..);
 }

在模板中,

 <ngb-datepicker #dp ></ngb-datepicker>

注意:您需要使用AfterViewInit接口实现该组件.并将NgbDatepicker,ViewChild和AfterViewInit导入component.ts

note: you need to implement the component using AfterViewInit interface. and import NgbDatepicker, ViewChild and AfterViewInit to the component.ts

这篇关于Angular 2 ngb-datepicker navigationTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆