I get this error The ng-model for md-datepicker must be a Date instance. Currently the model is a: string. I use the moment ..
in sight
<md-datepicker ng-model="Model.currentContact.getSetIncorporated" ng-model-options="{ getterSetter: true }" md-placeholder="Enter date"></md-datepicker>
in the model
Contact.prototype.getSetIncorporated = function(date) {
if (arguments.length) {
this.company.information.incorporatedObject = date;
this.company.information.incorporated = moment.utc(date).format('X');
}
if (!this.company.information.incorporatedObject) {
if (this.company.information.incorporated !== '') {
this.company.information.incorporatedObject = moment.utc(this.company.information.incorporated, 'X').toDate();
} else {
this.company.information.incorporatedObject = null;
}}
return this.company.information.incorporatedObject;
}
I also tried several mdLocale.formatDate and parseDate. Current version
$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 this line 2016-09-10T22:00:00.000Z
When I convert this string to a Date object with a new Date (), I get the correct result displayed in mdDatePicker, but I also get
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
which slows down my page.
Alexa source
share