简体   繁体   English

@ syncfusion / ej2-angular-calendars datepicker与反应形式一起使用时获取以前的值

[英]@syncfusion/ej2-angular-calendars datepicker getting previous values when using with reactive forms

In my angular 8 app, I am using @syncfusion/ej2-angular-calendars for showing calendar. 在我的angular 8应用程序中,我使用@syncfusion/ej2-angular-calendars显示日历。

my html is like 我的HTML就像

<form [formGroup]="visitsForm">
    <div class="disp-in-b mr-bt-sm">
        <ejs-datepicker #ejDatePicker formControlName="visitDate" [value] = "" name="visitDate" id='datepicker' placeholder="{{ 'general.selDate' | translate }}" format="dd/MM/yyyy" (change)="filterVisits()"></ejs-datepicker>
    </div>
    <div class="disp-in-b inline-checkbox text-center float-right" formGroupName="visitType" (change)="filterVisits()">
        <label class="checkbox-inline">
            <input type="checkbox" value="" id="appointments" formControlName="appointments">
               {{ 'general.appointments' | translate }}
        </label>
        <label class="checkbox-inline">
            <input type="checkbox" value="" id="consultation" formControlName="consultation">
             {{ 'general.consultation' | translate }}
        </label>
        <label class="checkbox-inline">
            <input type="checkbox" value="" id="tokens" formControlName="tokens">
            {{ 'general.tokens' | translate }}
        </label>
    </div>
</form>

And in my component file, I have the below function 在我的组件文件中,我具有以下功能

filterVisits() {
    const formVals = this.visitsForm.value;
    console.log(this.visitsForm.value);
}

I am getting the value of the date filed as null at the first date change. 我在第一次更改日期时获得的日期null Then if I change the date again, I am getting the previously selected date but not the current selected date. 然后,如果我再次更改日期,我得到的是先前选择的日期,而不是当前选择的日期。 But the change in the check boxes are working fine. 但是复选框的change工作正常。

I selected date "21/08/2019" and the value in this.form.value is like 我选定的日期“21/08/2019”,并在值this.form.value

{
    visitDate: ""
    visitType: {appointments: "", consultation: "", tokens: ""}
    __proto__: Object
}

Then I selected the date "10/08/2019" and the value in this.form.value is like 然后我选择了日期“ 10/08/2019”, this.form.value的值就像

{
    visitDate: Wed Aug 21 2019 00:00:00 GMT+0530 (India Standard Time) {}
    visitType: {appointments: "", consultation: "", tokens: ""}
    __proto__: Object
}

It is supposed to show the date 10/08/2019 instead of 21/08/2019 . 应该显示日期10/08/2019而不是21/08/2019

What am I doing wrong here? 我在这里做错了什么? Please help to solve this. 请帮助解决此问题。

Syncfusion form component values are after change event has been raised. Syncfusion表单组件值是在引发更改事件之后得出的。 So, you can take the value from formObject in change event, then you can get the previous value. 因此,您可以在change事件中从formObject中获取值,然后可以获取先前的值。 For this scenario, you can get the updated value in form object using blur event. 对于这种情况,您可以使用blur事件获取表单对象中的更新值。 Please refer the below sample. 请参考以下示例。

Sample link: https://stackblitz.com/edit/angular-krvj7d?file=app.component.ts . 样本链接: https : //stackblitz.com/edit/angular-krvj7d?file=app.component.ts

暂无
暂无

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

相关问题 通过@syncfusion/ej2-angular-calendars 在 ejs-datetimepicker 中默认将 datetimepicker 输入字段设置为空 - set datetimepicker input field to empty by default in ejs-datetimepicker by @syncfusion/ej2-angular-calendars Syncfusion ej2-angular-calendars 包需要映射到 systemjs.config.js 但这个文件在 Angular-cli 中不再存在 - Syncfusion ej2-angular-calendars package need to be mapped in systemjs.config.js but this file doesn't exists anymore in Angular-cli Angular 9 Reactive Forms:使用 trackBy 时复选框未更新 - Angular 9 Reactive Forms: checkbox not getting updated when using trackBy 使用 Syncfusion ej-angular 使用 Angularjs 在形状中添加 HTML 元素可以帮助我吗 - Can some help me with the Addition of HTML elements within the Shapes using Syncfusion ej-angular using the Angularjs 使用 angular 反应式 forms 我在 ngOnInIt 中设置的默认值没有得到反映 - using angular reactive forms the defaults values i was setting in ngOnInIt are not getting reflected @ syncfusion / ej2-angular-buttons的兼容角度和打字稿版本 - angular and typescript compatible versions for @syncfusion/ej2-angular-buttons 在Angular反应性表单中未获取多个复选框的值 - Not getting the values of multiple check boxes in Angular Reactive Forms md-datepicker +反应形式+ Firebase +角4 - md-datepicker + reactive forms + firebase + angular 4 反应形式-在Angular中追加值 - Reactive Forms - Appending Values in Angular 角度应用程序构建期间./node_modules/@syncfusion/ej2-angular-richtexteditor/@syncfusion/ej2-angular-richtexteditor.es5.js中的错误 - Error in ./node_modules/@syncfusion/ej2-angular-richtexteditor/@syncfusion/ej2-angular-richtexteditor.es5.js during build of angular application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM