I have an issue with my code involving the ion-datetime
and ion-check-box
. I want it so that when a date is selected, the checkbox should automatically be set to false
. Similarly, if the checkbox is clicked, the ion-datetime
value should be cleared.
Link to Screenshot
<form [formGroup]="registrationForm">
<ion-item>
<ion-label floating>Fecha Fin</ion-label>
<ion-datetime displayFormat="DD-MM-YYYY" formControlName="date_end"
(ngModelChange)="checkCheckEndDate()">
</ion-datetime>
</ion-item>
</form>
<ion-item>
<ion-label>Trabajo aquí actualmente</ion-label>
<ion-checkbox (click)="addValue()" [(ngModel)]="checked"></ion-checkbox>
</ion-item>
The component variable for the checkbox is defined as checked: boolean = false;
Constructor:
this.registrationForm = formBuilder.group({
date_end: ['',]
});
Special Functions:
addValue(): void {
alert("addValue"+this.checked);
if(this.checked){
this.registrationForm.controls['date_end'].setValue('');
}
}
checkCheckEndDate(){
alert("checkCheckEndDate");
if(this.registrationForm.controls['date_end'])
{
alert("if"+this.registrationForm.controls['date_end'].value)
this.checked=false;
alert(this.checked);
}else{
alert("no"+this.registrationForm.controls['date_end'].value)
this.checked=true;
alert(this.checked);
}
}
My question is, why does checkCheckEndDate()
execute when I click on the checkbox?