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

Commit

Permalink
feat($compile): mark scope creation with ng-scope class
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Feb 22, 2012
1 parent 4a051ef commit cb10ccc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/service/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function $CompileProvider($provide) {
var element = cloneConnectFn
? JQLitePrototype.clone.call(templateElement) // IMPORTANT!!!
: templateElement;
element.data('$scope', scope);
element.data('$scope', scope).addClass('ng-scope');
if (cloneConnectFn) cloneConnectFn(element, scope);
if (linkingFn) linkingFn(scope, element, element);
return element;
Expand Down Expand Up @@ -371,6 +371,7 @@ function $CompileProvider($provide) {

if (directive.scope) {
assertNoDuplicate('new scope', newScopeDirective, directive, element);
element.addClass('ng-scope');
newScopeDirective = directive;
}

Expand Down
6 changes: 3 additions & 3 deletions test/directivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ describe("directive", function() {
$rootScope.$digest();
$rootScope.dynCls = 'foo';
$rootScope.$digest();
expect(element[0].className).toBe('ui-panel ui-selected foo');
expect(element[0].className).toBe('ui-panel ui-selected ng-scope foo');
}));


it('should not add duplicate classes', inject(function($rootScope, $compile) {
element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);
$rootScope.dynCls = 'panel';
$rootScope.$digest();
expect(element[0].className).toBe('panel bar');
expect(element[0].className).toBe('panel bar ng-scope');
}));


Expand All @@ -279,7 +279,7 @@ describe("directive", function() {
$rootScope.$digest();
$rootScope.dynCls = 'window';
$rootScope.$digest();
expect(element[0].className).toBe('bar window');
expect(element[0].className).toBe('bar ng-scope window');
}));


Expand Down
9 changes: 6 additions & 3 deletions test/service/compilerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,21 @@ describe('$compile', function() {
toEqual('<div factory-error linking-error template-error>');
expect($exceptionHandler.errors[2][0]).toEqual('LinkingError');
expect(ie($exceptionHandler.errors[2][1])).
toEqual('<div factory-error linking-error template-error>');
toEqual('<div class="ng-scope" factory-error linking-error template-error>');


// crazy stuff to make IE happy
function ie(text) {
var list = [],
parts;
parts, elementName;

parts = lowercase(text).
replace('<', '').
replace('>', '').
split(' ');
elementName = parts.shift();
parts.sort();
parts.unshift(elementName);
forEach(parts, function(value, key){
if (value.substring(0,3) == 'ng-') {
} else {
Expand Down Expand Up @@ -888,6 +890,7 @@ describe('$compile', function() {
it('should allow creation of new scopes', inject(function($rootScope, $compile, log) {
element = $compile('<div><span scope><a log></a></span></div>')($rootScope);
expect(log).toEqual('LOG; log-002-001; 002');
expect(element.find('span').hasClass('ng-scope')).toBe(true);
}));


Expand All @@ -913,7 +916,7 @@ describe('$compile', function() {
expect(function(){
$compile('<div class="scope-a; scope-b"></div>');
}).toThrow('Multiple directives [scopeA, scopeB] asking for new scope on: ' +
'<' + (msie < 9 ? 'DIV' : 'div') + ' class="scope-a; scope-b">');
'<' + (msie < 9 ? 'DIV' : 'div') + ' class="scope-a; scope-b ng-scope">');
}));


Expand Down

0 comments on commit cb10ccc

Please sign in to comment.