I've made a calendar in my Angular app and I'm trying to pass a specific date that the user clicks on to a child component. The child component is declared like below:
<app-day-view [date]="dateToPass | date:'yyyy-MM-dd'"></app-day-view>
And the child component is set up to take in the input property correctly too:
import { Component, OnInit, Input, Output } from '@angular/core';
import { DateHandlerService } from './../../_services/date-handler.service';
declare var $: any;
@Component({
selector: 'app-day-view',
templateUrl: './day-view.component.html',
styleUrls: ['./day-view.component.css']
})
export class DayViewComponent implements OnInit {
@Input() date;
dateString: string;
constructor(public dateHandler: DateHandlerService) { }
ngOnInit() {
$('#dayModal').on('shown.bs.modal', this.getDateString);
}
getDateString() {
//this.dateString = this.dateHandler.convertToOutDate(this.date);
}
}
The intended behaviour is that I click one of the days in my calendar and <app-day-view>, which is a modal, opens, takes dateToPass, which I've confirmed already stores the correct date, and sends it to the child component. This template doesn't throw any errors, but by the time I check the date inside the DayViewComponent, it's undefined.
I assumed it was an issue caused by the child component existing in the parent component before being opened. The date input property would technically be undefined until I clicked on a day in the calendar, after which it would suddenly become defined, but I'm not sure if Angular input properties work like this. To get around this, I used JQuery to check the modal's shown.bs.modal event, and I only try to use the date after that event has fired, but the date still seems to come out as undefined.