У меня есть const
, который был объявлен в другой функции.Как я могу получить доступ к этому значению в следующей функции?
Речь идет о const selectedDatePicker = moment
, к которому я хочу обратиться позже в моей функции getAppointmentTimesById()
.Я могу успешно сохранить журнал, но не могу получить к нему доступ позже.Когда я пытаюсь сделать это с this.selectedDatePicker
, ничего не происходит.
selectedDate: string;
selectedDatePicker: string;
onChangeDate(Date) {
console.log(Date);
this.selectedDate = Date;
const selectedDatePicker = moment(
Date,
'ddd MMM D YYYY HH:mm:ss GMTzz [(Mitteleuropäische Sommerzeit)]'
).format('YYYY-MM-DD');
console.log('test' + selectedDatePicker);
// check if a value exists and use it
if (this.selectedAppointmentTypeId) {
this.onChangeTypeId(this.selectedAppointmentTypeId);
}
}
onChangeTypeId(TypeId) {
console.log(TypeId);
this.selectedAppointmentTypeId = TypeId;
this.apiService
.getAppointmentTimesById(
this.selectedAppointmentTypeId,
this.selectedAppointmentLocation,
this.selectedDatePicker
)
.subscribe((data: Array<object>) => {
this.appointmentTimes = data;
console.log(data);
});
}