Material: md-datepicker: Date not updated on model updates

Created on 6 Feb 2016  路  2Comments  路  Source: angular/material

Hi,

The date display is not getting updated when the model value is updated externally. See fiddle here.

Is there a workaround for this?

Thanks,
-dave

Most helpful comment

Hey @dratchkov,

You can find more information on a previous tracked issue on AngularJS https://github.com/angular/angular.js/issues/13224

Just summarizing:

  • The problem is, when you increment the day value, the actual date object will have the same reference id, so ngModel won't detect it.
  • Because ngModel will always compare $viewValue with $modelValue (See here) it won't detect any change.
  • So as you can see in the demo below (or in the issue) you should create a clone of the date, which has a new reference id -> and then the ngModelCtrl can detect the change.

Here a little demo - http://codepen.io/DevVersion/pen/zrmeXR

All 2 comments

Hey @dratchkov,

You can find more information on a previous tracked issue on AngularJS https://github.com/angular/angular.js/issues/13224

Just summarizing:

  • The problem is, when you increment the day value, the actual date object will have the same reference id, so ngModel won't detect it.
  • Because ngModel will always compare $viewValue with $modelValue (See here) it won't detect any change.
  • So as you can see in the demo below (or in the issue) you should create a clone of the date, which has a new reference id -> and then the ngModelCtrl can detect the change.

Here a little demo - http://codepen.io/DevVersion/pen/zrmeXR

Thanks @DevVersion!

Was this page helpful?
0 / 5 - 0 ratings