I am getting this error The ng-model for md-datepicker must be a Date instance. Currently the model is a: string
. I am using moment..
in view
<md-datepicker ng-model="Model.currentContact.getSetIncorporated" ng-model-options="{ getterSetter: true }" md-placeholder="Enter date"></md-datepicker>
in 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;
}
Also I have tried several mdLocale.formatDate and parseDate. Current version is
$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 is sending this string 2016-09-10T22:00:00.000Z
When I convert that string to Date object with new Date(), I get right result showing in mdDatePicker but I get also
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
which brakes my page.