Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

fix(ng-repeat): should correctly handle detached state #697

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class NgRepeatDirective {
}

_onCollectionChange(Iterable collection) {
if (!_scope.isAttached) return;
dom.Node previousNode = _blockHole.placeholder; // current position of the
// node
dom.Node nextNode;
Expand Down
23 changes: 21 additions & 2 deletions test/directive/ng_repeat_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ main() {
beforeEach(inject((Injector injector, Scope $rootScope, Compiler compiler, DirectiveMap _directives) {
$exceptionHandler = injector.get(ExceptionHandler);
scope = $rootScope;
$compile = (html) {
$compile = (html, [blockScope]) {
element = $(html);
var blockFactory = compiler(element, _directives);
var block = blockFactory(injector, element);
var blockInjector = injector;
if (blockScope != null) {
blockFactory.bind(injector)(blockScope);
} else {
blockFactory(blockInjector, element);
}
return element;
};
directives = _directives;
Expand Down Expand Up @@ -404,5 +409,19 @@ main() {
});
});


it('should correctly handle detached state', () {
scope.context['items'] = [1];

var parentScope = scope.createChild(new PrototypeMap(scope.context));
element = $compile(
'<ul>' +
'<li ng-repeat="item in items">{{item}}</li>' +
'</ul>', parentScope);

parentScope.destroy();
expect(scope.apply).not.toThrow();
});

});
}