md-datepicker has error style when I set the model to a date from number milliseconds
I have two datepickers that I load the date from a response from the server. The date is returned as a number milliseconds:
1454968800000
1455055200000
I use
$scope.offerInfo.validTo = new Date(data.validTo);
$scope.offerInfo.validFrom = new Date(data.validFrom);
and it appears like that in the web page:
screen
This is my html:
<md-content class="hide-scroll-bar-x">
<label>Starting on</label>
<md-datepicker ng-model="offerInfo.validFrom" md-min-date="yesterday" md-placeholder="Enter date" ng-required="true"></md-datepicker>
</md-content>
I set yesterday like that:
$scope.yesterday = new Date();
$scope.yesterday.setDate($scope.yesterday.getDate() - 1);
As you can see, the dates are not in the min-date range (issue posted on 03.03).
I did a research about my problem, but I didn't find anything useful that worked for me.
I tried creating a date from milliseconds, and set the min date to one day less. Can you explain clearly? Can u recreate the bug in this pen
Unfortunately, I could not recreate the bug, but I did a comparison of the HTML and the type of value that is set in the model when I create new Date(*milliseconds*) and when I choose a date from the picker. The HTML difference is that when the date is set with new Date(*milliseconds*), there's a class md-datepicker-invalid. There is no difference in the date object from new Date(*milliseconds*) and picked from the picker.
The case is:
I call an $http.get request to my server, the guy returns me an object from a DTO class with the dates as java.util.Date objects. I use the angular $q service and in the then() function I set the model to bind to the picker. When I refresh the HTML page, they go with error class. BUT if I call the same $http.get request without refreshing the HTML, they are fixed and everything is okay. I don't think I want to make two requests to get the info, because it's not just dates.