如何在角度剑道日期选择器上的日期选择器上设置值时调用事件

问题描述 投票:0回答:1

我有两个日期选择器(我的角度格式)(开始日期和结束日期),我想将结束日期的最小值设置为开始日期。我在开始日期更改值时调用了一个方法,该方法将最小值设置为结束日期(将开始日期设置为结束日期的最小日期)。当我在编辑模式下打开表单时,填充数据,当时我想根据开始日期设置结束日期的最小值,因此出现验证错误。 (以前分配的[min]仍然存在于我要ti重置的this.min变量中)如何执行此操作?

   <kendo-datepicker 
        formControlName="startDate" placeholder="Start Date" [format]="'MM/dd/yyyy'" (valueChange)=selectedStartDate() required>
   </kendo-datepicker>

   <kendo-datepicker 
        formControlName="endDate" placeholder="END Date" [format]="'MM/dd/yyyy'" [min] = "min" required>
   </kendo-datepicker>

app.component.ts

    min:Date;
    public selectedStartDate(){
        const formModel = this.specialDayFormGroup.value;
         if (formModel.startDate) {
          this.min = new Date(formModel.startDate);
        }
    }
angular typescript kendo-ui
1个回答
0
投票

import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
        <div class="example-config">
            <p>Only values between {{min | kendoDate:'d'}} and {{max | kendoDate:'d'}} are valid</p>
            <p>Errors: {{ dateModel.errors | json }}</p>
        </div>
        <div class="example-wrapper">
            <p>Select a date:</p>
            <kendo-datepicker
                [min]="min"
                [max]="max"
                [(ngModel)]="value"
                #dateModel="ngModel"
                (valueChange)=selectedStartDate()
            ></kendo-datepicker>

            <kendo-datepicker
                [min]="min2"
                [max]="max"
                [(ngModel)]="value"
                #dateModel="ngModel"
            ></kendo-datepicker>
        </div>
    `
})
export class AppComponent {
    public min: Date = new Date(2020, 4, 10);
    public min2: Date = new Date(2020, 4, 10);
    public max: Date = new Date(2020, 9, 10);
    public value: Date = new Date(2020, 4, 10);    
    public value2: Date = new Date(2020, 4, 10);

    public selectedStartDate(){
this.min2 = this.value;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.