diff options
| author | Igor Minar | 2012-03-23 11:46:54 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-03-23 11:46:54 -0700 | 
| commit | 5390fb37d2c01937922613fc57df4986af521787 (patch) | |
| tree | a95b890336212fde26379270eeb85e0e5f301e6a | |
| parent | 8d7e6948496ff26ef1da8854ba02fcb8eebfed61 (diff) | |
| download | angular.js-5390fb37d2c01937922613fc57df4986af521787.tar.bz2 | |
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
| -rw-r--r-- | src/service/compiler.js | 2 | ||||
| -rw-r--r-- | test/service/compilerSpec.js | 19 | 
2 files changed, 15 insertions, 6 deletions
diff --git a/src/service/compiler.js b/src/service/compiler.js index 784b8a3c..9e03f186 100644 --- a/src/service/compiler.js +++ b/src/service/compiler.js @@ -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 { diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js index a95e9eb3..d7ecdafc 100644 --- a/test/service/compilerSpec.js +++ b/test/service/compilerSpec.js @@ -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');            })          ); @@ -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');            })          );        });  | 
