I encountered an issue where the error message
The ng-model for md-datepicker must be a Date instance. Currently the model is a: string
appeared. I am utilizing moment.js library to handle dates.
Within the view section:
<md-datepicker ng-model="Model.currentContact.getSetIncorporated" ng-model-options="{ getterSetter: true }" md-placeholder="Enter date"></md-datepicker>
And in the model section:
Contact.prototype.getSetIncorporated = function(date) {
if (arguments.length) {
this.company.information.incorporatedObject = date;
this.company.information.incorporated = moment.utc(date).format('X');
}
// rest of the function...
}
I have also attempted using different methods like mdLocale.formatDate and parseDate. The current version looks like this:
$mdDateLocale.formatDate = function(date) {
return moment(date).format('YYYY/MM/DD');
};
$mdDateLocale.parseDate = function(dateString) {
var m = moment(dateString, 'YYYY/MM/DD', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
The server sends a date string like this: 2016-09-10T22:00:00.000Z
Converting this string to a Date object using new Date() displays the correct result in the mdDatePicker but triggers an error message
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
, causing issues on my page.