aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ng/rootScope.js2
-rw-r--r--test/ng/rootScopeSpec.js17
2 files changed, 18 insertions, 1 deletions
diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js
index 10b31dd1..0892843d 100644
--- a/src/ng/rootScope.js
+++ b/src/ng/rootScope.js
@@ -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;
diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js
index cd8d4109..cac7c160 100644
--- a/test/ng/rootScopeSpec.js
+++ b/test/ng/rootScopeSpec.js
@@ -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']);
+ });
});