[英]Ngb DatePicker - month not changing from current month even the date is changed to next month
when I try to navigate from the date for next month by the logic .It does apply to the next month date but calender view is not changing to the appropriate month.当我尝试通过逻辑从下个月的日期导航时。它确实适用于下个月的日期,但日历视图不会更改为适当的月份。
var newDate = new NgbDate(this.deliveryDate.year,this.deliveryDate.month,this.deliveryDate.day) var newDate = new NgbDate(this.deliveryDate.year,this.deliveryDate.month,this.deliveryDate.day)
let date = this.calender.getNext(newDate,"d",1)
From NgbDatepicker - Basic Datepicker , it requires从NgbDatepicker - Basic Datepicker ,它需要
dp.navigateTo(/* date */)
to update the Calendar view.更新日历视图。
To do the calendar navigation in the component,要在组件中进行日历导航,
Get the NgbDatepicker
from HTML with id: "dp" via @ViewChild()
.通过
@ViewChild()
从带有 id: "dp" 的 HTML 中获取NgbDatepicker
。
The below code would only return the Date value but not update the Calendar view.下面的代码只会返回 Date 值,但不会更新 Calendar 视图。 At the same time, you need "m" to update the month.
同时,您需要“m”来更新月份。
this.calendar.getNext(newDate, 'm', 1);
this.dp.navigateTo(date);
import { Component, ViewChild } from '@angular/core';
import {
NgbDateStruct,
NgbCalendar,
NgbDate,
NgbDatepicker,
} from '@ng-bootstrap/ng-bootstrap';
export class NgbdDatepickerBasic {
...
@ViewChild('dp') dp: NgbDatepicker;
toNextMonth() {
var newDate = new NgbDate(
this.model.year,
this.model.month,
this.model.day
);
let date = this.calendar.getNext(newDate, 'm', 1);
this.dp.navigateTo(date);
}
}
<button class="btn btn-sm btn-outline-primary me-2" (click)="toNextMonth()">To Next month</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.