I am using an Angular Material Date Picker application in my project which is a reservation form. What I want is for the user to select the date through the Date Picker. The Date Picker will have a filter that will show which dates are open and which aren't. In order for the Date Picker to know which dates are available it must make a call to one of my Services which returns an Observable. Here is my HTML code for the Date Picker:
<mat-form-field>
<label>
<input matInput [matDatepickerFilter]="dateFilter" required [matDatepicker]="picker" placeholder="Choose a date"
formControlName="date">
</label>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
and dateFilter():
dateFilter = (d: Date): boolean => {
if(monthIsSame(d) {
..// have a return statement that process a global variable: 'month: Day[]'
} else {
// the user hit the arrow at the top that switches months
//
// have a process that sets the 'month' variable to a new array of Days that was gotten
// through a RESTful api in one of my services.
// Somehow there must be a loading wheel here until the result from my server comes back and
// month is set to the new current month, and then a return statement that process a month
}
};
The problem is every time the user switches months, the calendar must load the month availability from the backside server, but the code from the server returns an Observable. Somehow the calendar must show a loading wheel until a value comes back from the subscribe method of the observable, and the calendar will get populated with the available dates.
Any help is greatly appreciated, and if I'm coming at this from the completely wrong way, please tell me. Thanks!
Edits:
Note: when I change the return type of my filter to Observable<boolean>
it sets all of the dates to be available.
I found the following post. Would it be somehow possible have a callback function that gets called when the user switches months and run my http request and load the results to a local variable. The only problem to this is that somehow the calendar would have to show a loading wheel until the callback function finishes.