【问题标题】:Angular: when I press 'n' key, in the input field date, I want my day to move to the next dayAngular:当我按“n”键时,在输入字段日期中,我希望我的一天移到第二天
【发布时间】:2022-06-13 20:29:05
【问题描述】:

我正在做这个项目,当我插入“n”键时,我需要帮助来增加一天的时间 这是我一直在做的,仍然没有任何改变

addDays($event) {
    const date = new Date();
    if ($event.key === 'n') {
      // add a day
      date.setDate(date.getDate() + 1);
    }
  }

html:

<input matInput id="datePicker-{{rowIndex}}" [matDatepicker]="datePicker" [(ngModel)]="row.date" required maxlength="10" (change)="isOccurrenceDateValid(rowIndex)" 
            class="mat-input-element-style" **(keydown)="addDays($event, rowIndex)"**>

【问题讨论】:

  • 我不确定它是否已被指出,但您的第一部分代码似乎不正确,您与 date 有冲突吗?您只是在修改 const date 吗?你能分享更多代码吗?

标签: angular date


【解决方案1】:

这是我刚刚创建的 stackblitz 演示,check it out

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2022-06-16
    • 2021-11-30
    相关资源
    最近更新 更多