根据 angular(setvalue) 中的先前日期选择器自动设置日期选择器值

set datepicker value automatically based on previous datepicker in angular(setvalue)

我有两个日期选择器 picker1picker2。我想要做的是,当我 select picker1 中的日期时,picker2 应该自动得到 selected picker2 中的日期应该是 picker1

中的日期后 60 天

例如,如果在 picker1 中是 2021 年 3 月 1 日,在 picker2

中应该是 2021 年 4 月 29 日

我在Whosebug 中搜索了各种解决方案,但找不到确切的解决方案。 如果你们知道请帮忙

日期选择器1:

                       <td>
                          <mat-form-field >
                            <input matInput readonly [matDatepicker]="picker1" formControlName="startdate" 
                            (dateChange)="setDate($event.value)"placeholder="Start Date">
                            <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
                            <mat-datepicker #picker1></mat-datepicker>
                        </mat-form-field>
                    </td>

Datepicker2

                    <td>
                        <mat-form-field>
                            <input matInput readonly [matDatepicker]="picker2" formControlName="enddate" 
                              placeholder="End Date">
                            <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
                            <mat-datepicker #picker2></mat-datepicker>
                        </mat-form-field>
                    </td>

我的老师

    setDate(a) {
            this.datecheck = this.eventaddform.value.startdate+60
this.eventaddform.patchValue({
          expirydate: this.datecheck
    
    
        })
       }
  

我已经创建了一个示例 stackblitz 以防万一,如果你们需要一些东西

Stackblitz:https://stackblitz.com/edit/angular-date-picker-sample-fr-h19bes?file=app%2Fapp.component.html

使用来自 picker1dateChange 事件通过绑定 value

来设置 picker2

我创建了一个基本的 stackblitz 示例,删除了 Forms

DEMO

PS:将 60 添加到 2021 年 3 月 1 日得到 2021 年 4 月 30 日。因此您可以尝试添加 59