diff options
| author | Igor Minar | 2013-07-02 17:23:51 -0700 |
|---|---|---|
| committer | Igor Minar | 2013-07-02 22:35:39 -0700 |
| commit | 69f42b76548d00f52b231ec91150e4f0b008c730 (patch) | |
| tree | 5775f9ef1f2db5721f414c41800daae90b2c6152 /test | |
| parent | cbbe3bfe91526af0523c0b014895f78df6a983ed (diff) | |
| download | angular.js-69f42b76548d00f52b231ec91150e4f0b008c730.tar.bz2 | |
fix($compile): prevent infinite loop w/ replace+transclude directives
Previously if a template contained a directive that had a template
(sync or async) and the directive template was to replace the original
element and the directive template contained another directive on the
root element of this template and this new directive was an element
transclude directive then an infinite recursion would follow because
the compiler kept on re-adding and reapplying the original directive
to the replaced node.
This change fixes that.
Closes #2155
Diffstat (limited to 'test')
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index be4ff3e5..492f851d 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -454,6 +454,63 @@ describe('ngRepeat', function() { describe('nesting in replaced directive templates', function() { + it('should work when placed on a non-root element of attr directive with SYNC replaced template', + inject(function($templateCache, $compile, $rootScope) { + $compileProvider.directive('rr', function() { + return { + restrict: 'A', + replace: true, + template: '<div ng-repeat="i in items">{{i}}|</div>' + }; + }); + element = jqLite('<div><span rr>{{i}}|</span></div>'); + $compile(element)($rootScope); + $rootScope.$apply(); + expect(element.text()).toBe(''); + + $rootScope.items = [1, 2]; + $rootScope.$apply(); + expect(element.text()).toBe('1|2|'); + expect(sortedHtml(element)).toBe( + '<div>' + + '<!-- ngRepeat: i in items -->' + + '<div ng-repeat="i in items" rr="">1|</div>' + + '<div ng-repeat="i in items" rr="">2|</div>' + + '</div>' + ); + })); + + + it('should work when placed on a non-root element of attr directive with ASYNC replaced template', + inject(function($templateCache, $compile, $rootScope) { + $compileProvider.directive('rr', function() { + return { + restrict: 'A', + replace: true, + templateUrl: 'rr.html' + }; + }); + + $templateCache.put('rr.html', '<div ng-repeat="i in items">{{i}}|</div>'); + + element = jqLite('<div><span rr>{{i}}|</span></div>'); + $compile(element)($rootScope); + $rootScope.$apply(); + expect(element.text()).toBe(''); + + $rootScope.items = [1, 2]; + $rootScope.$apply(); + expect(element.text()).toBe('1|2|'); + expect(sortedHtml(element)).toBe( + '<div>' + + '<!-- ngRepeat: i in items -->' + + '<div ng-repeat="i in items" rr="">1|</div>' + + '<div ng-repeat="i in items" rr="">2|</div>' + + '</div>' + ); + })); + + it('should work when placed on a root element of attr directive with SYNC replaced template', inject(function($templateCache, $compile, $rootScope) { $compileProvider.directive('replaceMeWithRepeater', function() { |
