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

Commit cb10ccc

Browse files
committed
feat($compile): mark scope creation with ng-scope class
1 parent 4a051ef commit cb10ccc

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/service/compiler.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function $CompileProvider($provide) {
195195
var element = cloneConnectFn
196196
? JQLitePrototype.clone.call(templateElement) // IMPORTANT!!!
197197
: templateElement;
198-
element.data('$scope', scope);
198+
element.data('$scope', scope).addClass('ng-scope');
199199
if (cloneConnectFn) cloneConnectFn(element, scope);
200200
if (linkingFn) linkingFn(scope, element, element);
201201
return element;
@@ -371,6 +371,7 @@ function $CompileProvider($provide) {
371371

372372
if (directive.scope) {
373373
assertNoDuplicate('new scope', newScopeDirective, directive, element);
374+
element.addClass('ng-scope');
374375
newScopeDirective = directive;
375376
}
376377

test/directivesSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ describe("directive", function() {
261261
$rootScope.$digest();
262262
$rootScope.dynCls = 'foo';
263263
$rootScope.$digest();
264-
expect(element[0].className).toBe('ui-panel ui-selected foo');
264+
expect(element[0].className).toBe('ui-panel ui-selected ng-scope foo');
265265
}));
266266

267267

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

275275

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

285285

test/service/compilerSpec.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,21 @@ describe('$compile', function() {
189189
toEqual('<div factory-error linking-error template-error>');
190190
expect($exceptionHandler.errors[2][0]).toEqual('LinkingError');
191191
expect(ie($exceptionHandler.errors[2][1])).
192-
toEqual('<div factory-error linking-error template-error>');
192+
toEqual('<div class="ng-scope" factory-error linking-error template-error>');
193193

194194

195195
// crazy stuff to make IE happy
196196
function ie(text) {
197197
var list = [],
198-
parts;
198+
parts, elementName;
199199

200200
parts = lowercase(text).
201201
replace('<', '').
202202
replace('>', '').
203203
split(' ');
204+
elementName = parts.shift();
204205
parts.sort();
206+
parts.unshift(elementName);
205207
forEach(parts, function(value, key){
206208
if (value.substring(0,3) == 'ng-') {
207209
} else {
@@ -888,6 +890,7 @@ describe('$compile', function() {
888890
it('should allow creation of new scopes', inject(function($rootScope, $compile, log) {
889891
element = $compile('<div><span scope><a log></a></span></div>')($rootScope);
890892
expect(log).toEqual('LOG; log-002-001; 002');
893+
expect(element.find('span').hasClass('ng-scope')).toBe(true);
891894
}));
892895

893896

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

919922

0 commit comments

Comments
 (0)