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

Commit 666a383

Browse files
lgalfasoIgorMinar
authored andcommitted
refactor(bootstrap): Remove support for old bootstrap mechnanisms
Remove support for bootstrap detection using: * The element id * The element class. E.g. ``` <div id="ng-app">...</div> <div class="ng-app: module">...</div> ``` Removes reference to how to bootstrap using IE7 BREAKING CHANGE: If using any of the mechanisms specified above, then migrate by specifying the attribute `ng-app` to the root element. E.g. ``` <div ng-app="module">...</div> ``` Closes #8147
1 parent 9dce42b commit 666a383

File tree

3 files changed

+25
-81
lines changed

3 files changed

+25
-81
lines changed

docs/content/guide/bootstrap.ngdoc

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ initialization.
3838

3939
<html ng-app>
4040

41-
3. If you require IE7 support add `id="ng-app"`
42-
43-
<html ng-app id="ng-app">
44-
45-
4. If you choose to use the old style directive syntax `ng:` then include xml-namespace in `html`
41+
3. If you choose to use the old style directive syntax `ng:` then include xml-namespace in `html`
4642
to make IE happy. (This is here for historical reasons, and we no longer recommend use of
4743
`ng:`.)
4844

src/Angular.js

+15-35
Original file line numberDiff line numberDiff line change
@@ -1314,46 +1314,26 @@ function getNgAttribute(element, ngAttr) {
13141314
</example>
13151315
*/
13161316
function angularInit(element, bootstrap) {
1317-
var elements = [element],
1318-
appElement,
1317+
var appElement,
13191318
module,
1320-
config = {},
1321-
names = ['ng:app', 'ng-app', 'x-ng-app', 'data-ng-app'],
1322-
options = {
1323-
'boolean': ['strict-di']
1324-
},
1325-
NG_APP_CLASS_REGEXP = /\sng[:\-]app(:\s*([\w\d_]+);?)?\s/;
1326-
1327-
function append(element) {
1328-
element && elements.push(element);
1329-
}
1319+
config = {};
1320+
1321+
// The element `element` has priority over any other element
1322+
forEach(ngAttrPrefixes, function(prefix) {
1323+
var name = prefix + 'app';
13301324

1331-
forEach(names, function(name) {
1332-
names[name] = true;
1333-
append(document.getElementById(name));
1334-
name = name.replace(':', '\\:');
1335-
if (element.querySelectorAll) {
1336-
forEach(element.querySelectorAll('.' + name), append);
1337-
forEach(element.querySelectorAll('.' + name + '\\:'), append);
1338-
forEach(element.querySelectorAll('[' + name + ']'), append);
1325+
if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
1326+
appElement = element;
1327+
module = element.getAttribute(name);
13391328
}
13401329
});
1330+
forEach(ngAttrPrefixes, function(prefix) {
1331+
var name = prefix + 'app';
1332+
var candidate;
13411333

1342-
forEach(elements, function(element) {
1343-
if (!appElement) {
1344-
var className = ' ' + element.className + ' ';
1345-
var match = NG_APP_CLASS_REGEXP.exec(className);
1346-
if (match) {
1347-
appElement = element;
1348-
module = (match[2] || '').replace(/\s+/g, ',');
1349-
} else {
1350-
forEach(element.attributes, function(attr) {
1351-
if (!appElement && names[attr.name]) {
1352-
appElement = element;
1353-
module = attr.value;
1354-
}
1355-
});
1356-
}
1334+
if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
1335+
appElement = candidate;
1336+
module = candidate.getAttribute(name);
13571337
}
13581338
});
13591339
if (appElement) {

test/AngularSpec.js

+9-41
Original file line numberDiff line numberDiff line change
@@ -712,16 +712,14 @@ describe('angular', function() {
712712

713713
beforeEach(function() {
714714
element = {
715-
getElementById: function (id) {
716-
return element.getElementById[id] || [];
715+
hasAttribute: function (name) {
716+
return !!element[name];
717717
},
718718

719-
720-
querySelectorAll: function(arg) {
721-
return element.querySelectorAll[arg] || [];
719+
querySelector: function(arg) {
720+
return element.querySelector[arg] || null;
722721
},
723722

724-
725723
getAttribute: function(name) {
726724
return element[name];
727725
}
@@ -738,60 +736,30 @@ describe('angular', function() {
738736

739737
it('should look for ngApp directive as attr', function() {
740738
var appElement = jqLite('<div ng-app="ABC"></div>')[0];
741-
element.querySelectorAll['[ng-app]'] = [appElement];
742-
angularInit(element, bootstrapSpy);
743-
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC'], jasmine.any(Object));
744-
});
745-
746-
747-
it('should look for ngApp directive in id', function() {
748-
var appElement = jqLite('<div id="ng-app" data-ng-app="ABC"></div>')[0];
749-
jqLite(document.body).append(appElement);
750-
angularInit(element, bootstrapSpy);
751-
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC'], jasmine.any(Object));
752-
});
753-
754-
755-
it('should look for ngApp directive in className', function() {
756-
var appElement = jqLite('<div data-ng-app="ABC"></div>')[0];
757-
element.querySelectorAll['.ng\\:app'] = [appElement];
739+
element.querySelector['[ng-app]'] = appElement;
758740
angularInit(element, bootstrapSpy);
759741
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC'], jasmine.any(Object));
760742
});
761743

762744

763745
it('should look for ngApp directive using querySelectorAll', function() {
764746
var appElement = jqLite('<div x-ng-app="ABC"></div>')[0];
765-
element.querySelectorAll['[ng\\:app]'] = [ appElement ];
747+
element.querySelector['[x-ng-app]'] = appElement;
766748
angularInit(element, bootstrapSpy);
767749
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC'], jasmine.any(Object));
768750
});
769751

770752

771-
it('should bootstrap using class name', function() {
772-
var appElement = jqLite('<div class="ng-app: ABC;"></div>')[0];
773-
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrapSpy);
774-
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, ['ABC'], jasmine.any(Object));
775-
});
776-
777-
778753
it('should bootstrap anonymously', function() {
779754
var appElement = jqLite('<div x-ng-app></div>')[0];
780-
element.querySelectorAll['[x-ng-app]'] = [ appElement ];
755+
element.querySelector['[x-ng-app]'] = appElement;
781756
angularInit(element, bootstrapSpy);
782757
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, [], jasmine.any(Object));
783758
});
784759

785760

786-
it('should bootstrap anonymously using class only', function() {
787-
var appElement = jqLite('<div class="ng-app"></div>')[0];
788-
angularInit(jqLite('<div></div>').append(appElement)[0], bootstrapSpy);
789-
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, [], jasmine.any(Object));
790-
});
791-
792-
793761
it('should bootstrap if the annotation is on the root element', function() {
794-
var appElement = jqLite('<div class="ng-app"></div>')[0];
762+
var appElement = jqLite('<div ng-app=""></div>')[0];
795763
angularInit(appElement, bootstrapSpy);
796764
expect(bootstrapSpy).toHaveBeenCalledOnceWith(appElement, [], jasmine.any(Object));
797765
});
@@ -838,7 +806,7 @@ describe('angular', function() {
838806

839807
it('should bootstrap in strict mode when ng-strict-di attribute is specified', function() {
840808
bootstrapSpy = spyOn(angular, 'bootstrap').andCallThrough();
841-
var appElement = jqLite('<div class="ng-app" ng-strict-di></div>');
809+
var appElement = jqLite('<div ng-app="" ng-strict-di></div>');
842810
angularInit(jqLite('<div></div>').append(appElement[0])[0], bootstrapSpy);
843811
expect(bootstrapSpy).toHaveBeenCalledOnce();
844812
expect(bootstrapSpy.mostRecentCall.args[2].strictDi).toBe(true);

0 commit comments

Comments
 (0)