简体   繁体   English

Ngb DatePicker - 即使日期更改为下个月,月份也不会从当前月份更改

[英]Ngb DatePicker - month not changing from current month even the date is changed to next month

{{time}} {{时间}}

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 requiresNgbDatepicker - Basic Datepicker ,它需要

dp.navigateTo(/* date */)

to update the Calendar view.更新日历视图。

To do the calendar navigation in the component,要在组件中进行日历导航,

  1. Get the NgbDatepicker from HTML with id: "dp" via @ViewChild() .通过@ViewChild()从带有 id: "dp" 的 HTML 中获取NgbDatepicker

  2. 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);
  1. Navigate the Calendar with the new date value.使用新日期值导航日历。
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>

Sample StackBlitz Demo 示例 StackBlitz 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ngb-Datepicker 在弹出窗口中显示错误的月份 - ngb-Datepicker show wrong month on popup 更改月份时日期不正确 - Incorrect Date when changing month 如何在日期选择器中仅显示 3 个月作为当前日期的下拉列表,当当月完成时,我们将显示即将到来的 3 个月 - How to show only 3 months in datepicker as dropdown from current date and when the current month is completed then we have show the upcoming 3 months Angular和TypeScript-显示当前月份的最后日期 - Angular & TypeScript - Displaying the Last Date of the Current Month 日期解析月份格式 - Date parse month format 仅格式化日期月份 - Format Date Month only Angular 7 Mat datepicker - 如何将月份名称从短更改为长: - Angular 7 Mat datepicker - How to change the name of the month from short to long: Angular Material-Datepicker使选定值一个月达到最大值 - Angular Material - Datepicker make max value a month from selected value 试图从角度材料DatePicker中获取日,年和月 - Trying to just get the Day, Year and Month from angular material DatePicker 如果从 Angular 的 mat-datepicker 功能的日历中选择开始日期,如何动态设置月结束日期? - How to dynamically set month end date if start date is picked from the calendar of Angular's mat-datepicker functionality?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM