mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 23:34:42 +00:00
corrected repeater not removing when hash(instead of array) shrinks.
This commit is contained in:
parent
b628de9758
commit
6431efef8c
2 changed files with 25 additions and 9 deletions
|
|
@ -665,29 +665,28 @@ RepeaterUpdater.prototype = {
|
||||||
scope.set(this.iteratorExp, iterator);
|
scope.set(this.iteratorExp, iterator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var iteratorLength = iterator.length;
|
|
||||||
var childrenLength = this.children.length;
|
var childrenLength = this.children.length;
|
||||||
var cursor = this.view;
|
var cursor = this.view;
|
||||||
var time = 0;
|
var time = 0;
|
||||||
var child = null;
|
var child = null;
|
||||||
var keyExp = this.keyExp;
|
var keyExp = this.keyExp;
|
||||||
var valueExp = this.valueExp;
|
var valueExp = this.valueExp;
|
||||||
var i = 0;
|
var iteratorCounter = 0;
|
||||||
foreach(iterator, function(value, key){
|
foreach(iterator, function(value, key){
|
||||||
if (i < childrenLength) {
|
if (iteratorCounter < childrenLength) {
|
||||||
// reuse children
|
// reuse children
|
||||||
child = self.children[i];
|
child = self.children[iteratorCounter];
|
||||||
child.scope.set(valueExp, value);
|
child.scope.set(valueExp, value);
|
||||||
} else {
|
} else {
|
||||||
// grow children
|
// grow children
|
||||||
var name = self.prefix +
|
var name = self.prefix +
|
||||||
valueExp + " in " + self.iteratorExp + "[" + i + "]";
|
valueExp + " in " + self.iteratorExp + "[" + iteratorCounter + "]";
|
||||||
var childScope = new Scope(scope.state, name);
|
var childScope = new Scope(scope.state, name);
|
||||||
childScope.set('$index', i);
|
childScope.set('$index', iteratorCounter);
|
||||||
if (keyExp)
|
if (keyExp)
|
||||||
childScope.set(keyExp, key);
|
childScope.set(keyExp, key);
|
||||||
childScope.set(valueExp, value);
|
childScope.set(valueExp, value);
|
||||||
child = { scope:childScope, element:self.template(childScope, self.prefix, i) };
|
child = { scope:childScope, element:self.template(childScope, self.prefix, iteratorCounter) };
|
||||||
cursor.after(child.element);
|
cursor.after(child.element);
|
||||||
self.children.push(child);
|
self.children.push(child);
|
||||||
}
|
}
|
||||||
|
|
@ -695,10 +694,10 @@ RepeaterUpdater.prototype = {
|
||||||
var s = new Date().getTime();
|
var s = new Date().getTime();
|
||||||
child.scope.updateView();
|
child.scope.updateView();
|
||||||
time += new Date().getTime() - s;
|
time += new Date().getTime() - s;
|
||||||
i++;
|
iteratorCounter++;
|
||||||
});
|
});
|
||||||
// shrink children
|
// shrink children
|
||||||
for ( var r = childrenLength; r > iteratorLength; --r) {
|
for ( var r = childrenLength; r > iteratorCounter; --r) {
|
||||||
this.children.pop().element.remove();
|
this.children.pop().element.remove();
|
||||||
}
|
}
|
||||||
// Special case for option in select
|
// Special case for option in select
|
||||||
|
|
|
||||||
|
|
@ -503,6 +503,23 @@ BinderTest.prototype.testRepeaterAdd = function(){
|
||||||
assertEquals(doc.scope().get('items')[0].x, 'ABC');
|
assertEquals(doc.scope().get('items')[0].x, 'ABC');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){
|
||||||
|
var c = compile('<div ng-repeat="i in items">{{i}}</div>');
|
||||||
|
var items = {};
|
||||||
|
c.scope.set("items", items);
|
||||||
|
|
||||||
|
c.binder.updateView();
|
||||||
|
expect(c.node.find("div").size()).toEqual(0);
|
||||||
|
|
||||||
|
items.name = "misko";
|
||||||
|
c.binder.updateView();
|
||||||
|
expect(c.node.find("div").size()).toEqual(1);
|
||||||
|
|
||||||
|
delete items.name;
|
||||||
|
c.binder.updateView();
|
||||||
|
expect(c.node.find("div").size()).toEqual(0);
|
||||||
|
};
|
||||||
|
|
||||||
BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){
|
BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){
|
||||||
var a = compile('<div>{{error.throw()}}</div>');
|
var a = compile('<div>{{error.throw()}}</div>');
|
||||||
var doc = a.node.find('div');
|
var doc = a.node.find('div');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue