From c7155530e8056d24cfad01d53bdbcf5fe0456e3a Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Fri, 26 Jun 2015 17:43:31 +0300 Subject: [PATCH] fix($compile): throw error when requestng new and isolate scopes (async) While directives are not allowed to request both a new (normal) and an isolate scope on the same element, the relevant check was not performed correctly when the directive requesting the isolate scope had a lower priority and specified a `templateUrl`. In that case, the check was deferred until the template was fetched, but the info about other directives requesting a new (normal) scope was not properly preserved (in `previousCompileContext`). This commit fixes this, so now an error is thrown (as expected). Fixes #12215 Closes #12217 --- src/ng/compile.js | 3 ++- test/ng/compileSpec.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 85728ea01315..9123d8f7815c 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1654,7 +1654,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { previousCompileContext = previousCompileContext || {}; var terminalPriority = -Number.MAX_VALUE, - newScopeDirective, + newScopeDirective = previousCompileContext.newScopeDirective, controllerDirectives = previousCompileContext.controllerDirectives, newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective, templateDirective = previousCompileContext.templateDirective, @@ -1820,6 +1820,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode, templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, { controllerDirectives: controllerDirectives, + newScopeDirective: (newScopeDirective !== directive) && newScopeDirective, newIsolateScopeDirective: newIsolateScopeDirective, templateDirective: templateDirective, nonTlbTranscludeDirective: nonTlbTranscludeDirective diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 794a95a48ebf..f8e42da02110 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2370,7 +2370,7 @@ describe('$compile', function() { }) ); - it('should not allow more then one isolate scope creation per element', inject( + it('should not allow more than one isolate scope creation per element', inject( function($rootScope, $compile) { expect(function() { $compile('
'); @@ -2379,6 +2379,18 @@ describe('$compile', function() { }) ); + it('should not allow more than one isolate/new scope creation per element regardless of `templateUrl`', + inject(function($httpBackend) { + $httpBackend.expect('GET', 'tiscope.html').respond('
Hello, world !
'); + + expect(function() { + compile('
'); + $httpBackend.flush(); + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [scopeB, tiscopeA] ' + + 'asking for new/isolated scope on:
'); + }) + ); + it('should not allow more than one isolate scope creation per element regardless of directive priority', function() { module(function($compileProvider) { $compileProvider.directive('highPriorityScope', function() {