The Angular documentation says that ng-app value (module name) is optional. But does not describe angular's behaviour when there is no module name? So how does angular pick the root module ?
Does it create a generic module and injects all the available modules in it ?
it will be ng
and no, it won't inject other modules. Take a look at angular source code for function bootstrap
. So when angular is loaded, and document is ready, angularInit
will be invoked to find the element with ng-app
and module as well, then call bootstrap
. if no module is defined, you may refer to the logic below, ng
is unshifted to the modules array as a default module.
function bootstrap(element, modules) {
var doBootstrap = function() {
element = jqLite(element);
if (element.injector()) {
var tag = (element[0] === document) ? 'document' : startingTag(element);
throw ngMinErr('btstrpd', "App Already Bootstrapped with this Element '{0}'", tag);
}
modules = modules || [];
modules.unshift(['$provide', function($provide) {
$provide.value('$rootElement', element);
}]);
modules.unshift('ng');
var injector = createInjector(modules);
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', '$animate',
function(scope, element, compile, injector, animate) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);
return injector;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With