Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Infinite $digest Loop occur when using deep $watch on an object that contains an "Invalid Date". #8650

Closed
runtarm opened this issue Aug 18, 2014 · 0 comments

Comments

@runtarm
Copy link

runtarm commented Aug 18, 2014

Code to reproduce:

$scope.items = { date: new Date(undefined) };
$scope.$watch('items', angular.noop, true);

Plunker: http://plnkr.co/edit/jsb1nVTHMmi6ynnnlHTS?p=preview

This is probably because angular.equals use .getTime() to compare Date objects: Angular.js#L910.

return isDate(o2) && o1.getTime() == o2.getTime();

But .getTime() return NaN for an invalid Date object.

var invalidDate = new Date(undefined);
invalidDate.toString(); // return "Invalid Date"
invalidDate.getTime(); // return NaN

These issues might be related: #657 #4605

@btford btford added this to the Backlog milestone Aug 18, 2014
SekibOmazic added a commit to SekibOmazic/angular.js that referenced this issue Aug 21, 2014
…n object that contains an "Invalid Date"

Add better check for invalid dates in method equals.

fixes angular#8650
caitp pushed a commit that referenced this issue Aug 22, 2014
Make angular.equals() Date comparison NaN-aware to prevent infinite digest errors when a dealy watched
date has an invalid value.

Closes #8650
Closes #8715
@caitp caitp closed this as completed in 693e846 Aug 22, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants