From f9b80ed3752f63479ac0e2b8f75206ff2c9c64cb Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Mon, 10 Mar 2014 15:59:53 -0400 Subject: [PATCH] fix(ng-repeat): should correctly handle detached state --- lib/directive/ng_repeat.dart | 1 + test/directive/ng_repeat_spec.dart | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/directive/ng_repeat.dart b/lib/directive/ng_repeat.dart index 8e5d494dd..5770a1e03 100644 --- a/lib/directive/ng_repeat.dart +++ b/lib/directive/ng_repeat.dart @@ -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; diff --git a/test/directive/ng_repeat_spec.dart b/test/directive/ng_repeat_spec.dart index 9d60171ac..64908e29a 100644 --- a/test/directive/ng_repeat_spec.dart +++ b/test/directive/ng_repeat_spec.dart @@ -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; @@ -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( + '', parentScope); + + parentScope.destroy(); + expect(scope.apply).not.toThrow(); + }); + }); }