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

Commit

Permalink
fix($rootScope) ensure $watchCollection correctly handles arrayLike o…
Browse files Browse the repository at this point in the history
…bjects
  • Loading branch information
Gonzalo Ruiz de Villa authored and petebacondarwin committed May 2, 2013
1 parent dc9a580 commit 6452707
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function $RootScopeProvider(){
oldValue = newValue;
changeDetected++;
}
} else if (isArray(newValue)) {
} else if (isArrayLike(newValue)) {
if (oldValue !== internalArray) {
// we are transitioning from something which was not an array into array.
oldValue = internalArray;
Expand Down
17 changes: 17 additions & 0 deletions test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ describe('Scope', function() {
$rootScope.$digest();
expect(log).toEqual([ '[{},[]]' ]);
});

it('should watch array-like objects like arrays', function () {
var arrayLikelog = [];
$rootScope.$watchCollection('arrayLikeObject', function logger(obj) {
forEach(obj, function (element){
arrayLikelog.push(element.name);
})
});
document.body.innerHTML = "<p>" +
"<a name='x'>a</a>" +
"<a name='y'>b</a>" +
"</p>";

$rootScope.arrayLikeObject = document.getElementsByTagName('a')
$rootScope.$digest();
expect(arrayLikelog).toEqual(['x', 'y']);
});
});


Expand Down

0 comments on commit 6452707

Please sign in to comment.