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>
you can do it easily in component.ts
@ViewChild('dp') datepicker: NgbDatepicker;
then ,
ngAfterViewInit() {
this.datepicker.navigateTo(..);
}
in template ,
<ngb-datepicker #dp ></ngb-datepicker>
note: you need to implement the component using AfterViewInit interface. and import NgbDatepicker, ViewChild and AfterViewInit to the component.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With