[英]@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.