mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix($rootScope) ensure $watchCollection correctly handles arrayLike objects
This commit is contained in:
parent
dc9a580617
commit
6452707d40
2 changed files with 18 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue