Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6333d65

Browse files
committed
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
1 parent 1ce5d21 commit 6333d65

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ng/compile.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16541654
previousCompileContext = previousCompileContext || {};
16551655

16561656
var terminalPriority = -Number.MAX_VALUE,
1657-
newScopeDirective,
1657+
newScopeDirective = previousCompileContext.newScopeDirective,
16581658
controllerDirectives = previousCompileContext.controllerDirectives,
16591659
newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective,
16601660
templateDirective = previousCompileContext.templateDirective,
@@ -1820,6 +1820,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18201820
nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
18211821
templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
18221822
controllerDirectives: controllerDirectives,
1823+
newScopeDirective: (newScopeDirective !== directive) && newScopeDirective,
18231824
newIsolateScopeDirective: newIsolateScopeDirective,
18241825
templateDirective: templateDirective,
18251826
nonTlbTranscludeDirective: nonTlbTranscludeDirective

test/ng/compileSpec.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ describe('$compile', function() {
23702370
})
23712371
);
23722372

2373-
it('should not allow more then one isolate scope creation per element', inject(
2373+
it('should not allow more than one isolate scope creation per element', inject(
23742374
function($rootScope, $compile) {
23752375
expect(function() {
23762376
$compile('<div class="iscope-a; scope-b"></div>');
@@ -2379,6 +2379,18 @@ describe('$compile', function() {
23792379
})
23802380
);
23812381

2382+
it('should not allow more than one isolate/new scope creation per element regardless of `templateUrl`',
2383+
inject(function($httpBackend) {
2384+
$httpBackend.expect('GET', 'tiscope.html').respond('<div>Hello, world !</div>');
2385+
2386+
expect(function() {
2387+
compile('<div class="tiscope-a; scope-b"></div>');
2388+
$httpBackend.flush();
2389+
}).toThrowMinErr('$compile', 'multidir', 'Multiple directives [scopeB, tiscopeA] ' +
2390+
'asking for new/isolated scope on: <div class="tiscope-a; scope-b ng-scope">');
2391+
})
2392+
);
2393+
23822394
it('should not allow more than one isolate scope creation per element regardless of directive priority', function() {
23832395
module(function($compileProvider) {
23842396
$compileProvider.directive('highPriorityScope', function() {

0 commit comments

Comments
 (0)