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

fix($compile): fix missing error handling when new-scope directive is applied before isolated-scope directive #4421

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div class="iscope-a; high-priority-scope"></div>');
}).toThrowMinErr('$compile', 'multidir', 'Multiple directives [highPriorityScope, iscopeA] asking for new/isolated scope on: ' +
'<div class="iscope-a; high-priority-scope ng-scope">');
});
});


it('should create new scope even at the root of the template', inject(
function($rootScope, $compile, log) {
Expand Down