Ever since I made the switch from JavaScript to TypeScript (Version 2.1.5), I have been facing an issue with the code that filters date selection. Despite my efforts, I haven't been able to find a good fix for it yet.
Here are the two date-pickers: From and To:
<div class="form-group">
<label class="label label-letter-spacing">From </label>
<div class='input-group date' id='datepickerFrom'>
<md-datepicker ng-model="vm.dateFrom"></md-datepicker>
</div>
</div>
<div class="form-group">
<label class="label label-letter-spacing">To </label>
<div class='input-group date' id='datepickerTo'>
<md-datepicker ng-model="vm.dateTo" md-date-filter="vm.onlyGreaterThanFromDate" ></md-datepicker>
</div>
</div>
In my Controller.ts file, I have the following:
dateTo: Date;
dateFrom: Date;
onlyGreaterThanFromDate(date) {
if (this.dateFrom != undefined )
return (date.getTime() > this.dateFrom.getTime());
};
While debugging in Chrome browser, I noticed that the context changes when the method is executed, causing this to now represent the CalendarCtrl instead of my Controller, leading to this.dateFrom being undefined.
I've tried making some adjustments like setting dateFrom as static or private, but nothing seems to work. I'm still actively looking for a solution and would appreciate any comments or ideas on this matter. Thank you! :)