I've encountered an issue with the calendar icon for angular2's datepicker. Whenever I try to click on it, I keep getting this error:
TypeError: Cannot read property 'toggle' of undefined at Object.eval [as handleEvent] (AdmissionDialogComponent.html:1) at handleEvent (core.es5.js?de3d:11997) at callWithDebugContext (core.es5.js?de3d:13458) at Object.debugHandleEvent [as handleEvent] (core.es5.js?de3d:13046) at dispatchEvent (core.es5.js?de3d:8601) at eval (core.es5.js?de3d:9212) at HTMLButtonElement.eval (platform-browser.es5.js?41b7:2651) at ZoneDelegate.invokeTask (zone.js?6524:424) at Object.onInvokeTask (core.es5.js?de3d:3881) at ZoneDelegate.invokeTask (zone.js?6524:423)
Below are the codes I am using for setting up the start date and end date that are causing the issue:
<div class="col-sm-2">
<div class="input-group">
<input id="field_treatmentStartDate" type="text" class="form-control" name="treatmentStartDate" ngbDatepicker #tStartDateDp="ngbDatepicker"
*ngIf="admission.treatment" [(ngModel)]="admission.treatment.startDate" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" (click)="tStartDateDp.toggle()"><i class="fa fa-calendar"></i></button>
</span>
</div>
<div [hidden]="!(editForm.controls.treatmentStartDate?.dirty && editForm.controls.treatmentStartDate?.invalid)">
<small class="form-text text-danger" [hidden]="!editForm.controls.treatmentStartDate?.errors?.ZonedDateTimelocal" jhiTranslate="entity.validation.ZonedDateTimelocal">
This field should be a date and time.
</small>
</div>
<div [hidden]="!treatmentStartDateIsNull">
<small class="form-text text-danger">
Missing treatment start date.
</small>
</div>
</div>
<!-- start date -->
...
...
In the component.ts file, I have initialized empty values for the admission model in the "ngOnInit" function.
this.admission.patient = this.patient;
this.admission.bed = this.bed;
this.admission.bed.ward = this.ward;
this.admission.treatment = this.treatment;
Despite setting up blank attributes in the admission value, I'm confused as to why some parts are working while others are not. I have declared attributes like below in the ngOnInit function:
treatment: Treatment = new Treatment();