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

Commit

Permalink
fix($compile): create new (isolate) scopes for directives on root ele…
Browse files Browse the repository at this point in the history
…ments

previously we would not create them and it's causing all kinds of issues and accidental leaks

Closes #817
  • Loading branch information
IgorMinar committed Mar 23, 2012
1 parent 8d7e694 commit 5390fb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/service/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function $CompileProvider($provide) {
childLinkingFn = /* nodesetLinkingFn */ linkingFns[i++];

if (directiveLinkingFn) {
if (directiveLinkingFn.scope && !rootElement) {
if (directiveLinkingFn.scope) {
childScope = scope.$new(isObject(directiveLinkingFn.scope));
jqLite(node).data('$scope', childScope);
} else {
Expand Down
19 changes: 14 additions & 5 deletions test/service/compilerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,11 @@ describe('$compile', function() {
);


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

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


it('should treat new scope on new template as noop', inject(
it('should create new scope even at the root of the template', inject(
function($rootScope, $compile, log) {
element = $compile('<div scope-a></div>')($rootScope);
expect(log).toEqual('001');
expect(log).toEqual('002');
})
);


it('should create isolate scope even at the root of the template', inject(
function($rootScope, $compile, log) {
element = $compile('<div iscope></div>')($rootScope);
expect(log).toEqual('002');
})
);
});
Expand Down

0 comments on commit 5390fb3

Please sign in to comment.