diff --git a/src/ng/compile.js b/src/ng/compile.js index c44985fdee26..f587d0bdbe4c 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -794,18 +794,19 @@ function $CompileProvider($provide) { } if (directiveValue = directive.scope) { - newScopeDirective = newScopeDirective || directive; - // skip the check for directives with async templates, we'll check the derived sync directive when // the template arrives if (!directive.templateUrl) { - assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive, $compileNode); if (isObject(directiveValue)) { + assertNoDuplicate('new/isolated scope', newIsolateScopeDirective || newScopeDirective, directive, $compileNode); safeAddClass($compileNode, 'ng-isolate-scope'); newIsolateScopeDirective = directive; + } else { + assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive, $compileNode); } safeAddClass($compileNode, 'ng-scope'); } + newScopeDirective = newScopeDirective || directive; } directiveName = directive.name; diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 9a69824aaca3..f093deae937f 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1539,6 +1539,25 @@ describe('$compile', function() { }) ); + it('should not allow more than one isolate scope creation per element regardless of directive priority', function() { + module(function($compileProvider) { + $compileProvider.directive('highPriorityScope', function() { + return { + restrict: 'C', + priority: 1, + scope: true, + link: function() {} + } + }); + }); + inject(function($compile) { + expect(function(){ + $compile('
'); + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [highPriorityScope, iscopeA] asking for new/isolated scope on: ' + + '
'); + }); + }); + it('should create new scope even at the root of the template', inject( function($rootScope, $compile, log) {