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

Commit 5390fb3

Browse files
committed
fix($compile): create new (isolate) scopes for directives on root elements
previously we would not create them and it's causing all kinds of issues and accidental leaks Closes #817
1 parent 8d7e694 commit 5390fb3

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/service/compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function $CompileProvider($provide) {
324324
childLinkingFn = /* nodesetLinkingFn */ linkingFns[i++];
325325

326326
if (directiveLinkingFn) {
327-
if (directiveLinkingFn.scope && !rootElement) {
327+
if (directiveLinkingFn.scope) {
328328
childScope = scope.$new(isObject(directiveLinkingFn.scope));
329329
jqLite(node).data('$scope', childScope);
330330
} else {

test/service/compilerSpec.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,11 @@ describe('$compile', function() {
10351035
);
10361036

10371037

1038-
it('should allow more then one scope creation per element', inject(
1038+
it('should allow more one new scope directives per element, but directives should share' +
1039+
'the scope', inject(
10391040
function($rootScope, $compile, log) {
1040-
$compile('<div class="scope-a; scope-b"></div>')($rootScope);
1041-
expect(log).toEqual('001; 001');
1041+
element = $compile('<div class="scope-a; scope-b"></div>')($rootScope);
1042+
expect(log).toEqual('002; 002');
10421043
})
10431044
);
10441045

@@ -1064,10 +1065,18 @@ describe('$compile', function() {
10641065
);
10651066

10661067

1067-
it('should treat new scope on new template as noop', inject(
1068+
it('should create new scope even at the root of the template', inject(
10681069
function($rootScope, $compile, log) {
10691070
element = $compile('<div scope-a></div>')($rootScope);
1070-
expect(log).toEqual('001');
1071+
expect(log).toEqual('002');
1072+
})
1073+
);
1074+
1075+
1076+
it('should create isolate scope even at the root of the template', inject(
1077+
function($rootScope, $compile, log) {
1078+
element = $compile('<div iscope></div>')($rootScope);
1079+
expect(log).toEqual('002');
10711080
})
10721081
);
10731082
});

0 commit comments

Comments
 (0)