Skip to content

Commit 115086e

Browse files
committed
Bootstrapping Angular Applications Automatically
1 parent 30c6bd8 commit 115086e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/bootstrap.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var $ = require('jquery');
4+
var _ = require('lodash');
45
var publishExternalAPI = require('./angular_public');
56
var createInjector = require('./injector');
67

@@ -23,3 +24,29 @@ window.angular.bootstrap = function(element, modules, config) {
2324
}]);
2425
return injector;
2526
};
27+
28+
var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-'];
29+
$(document).ready(function() {
30+
var foundAppElement, foundModule, config = {};
31+
_.forEach(ngAttrPrefixes, function(prefix) {
32+
var attrName = prefix + 'app';
33+
var selector = '[' + attrName.replace(':', '\\:') + ']';
34+
var element;
35+
if (!foundAppElement &&
36+
(element = document.querySelector(selector))) {
37+
foundAppElement = element;
38+
foundModule = element.getAttribute(attrName);
39+
}
40+
});
41+
if (foundAppElement) {
42+
config.strictDi = _.some(ngAttrPrefixes, function(prefix) {
43+
var attrName = prefix + 'strict-di';
44+
return foundAppElement.hasAttribute(attrName);
45+
});
46+
window.angular.bootstrap(
47+
foundAppElement,
48+
foundModule ? [foundModule] : [],
49+
config
50+
);
51+
}
52+
});

0 commit comments

Comments
 (0)