Bootstrapping multiple modules in AngularJS

In this article we will be Understanding AngularJS Bootstrap Process talking about automatic Bootstrapping and manual Bootstrapping multiple modules in AngularJS.

Angular initiates automatically upon DOMContentLoaded event or when the angular.js script is downloaded to the browser and the document.readyState is set to complete.

At this point AngularJS looks for the ng-app directive which is the root of angular app compilation and tells about AngularJS part within DOM. When the ng-app directive is found then Angular will:

  1. Load the module associated with the directive.
  2. Create the application injector.
  3. Compile the DOM starting from the ng-app root element.

This process is called auto-bootstrapping.



You can manually initialized your angular app by using angular.bootstrap() function. This function takes the modules as parameters and should be called within angular.element(document).ready() function. The angular.element(document).ready() function is fired when the DOM is ready for manipulation.



AngularJS is automatically initialized for one module. But sometimes, it is required to bootstrap for multiple modules and it can be achieved by using two methods:

Automatic bootstrap (by combining multiple modules into one module)

You can combine multiple modules into single modules and your angular app will be automatically initialized for newly created module and other modules will act as dependent modules for newly created module.

For example, suppose you have two modules: module1 and model2, and you have to initialize your app automatically based on these two modules then you achieve this following way:

Manual bootstrap

 You can manually bootstrap your app by using angular.bootstrap() function, for multiple modules. The above example can be rewritten as for manual bootstrap process as given below:


What do you think?

I hope you have got, how to bootstrap your angular app based on multiple modules. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Arif Khoja
Arif Khoja is a Developer. He is a Javascript Enthusiatic who loves logical programming and has first hand experience in building a cutting edge internet product using Angular. He is also an open source freak and keen about learning and sharing. He writes Javascript both frontend and backend. He loves learning and sharing tech all the time. He also has a hands on experience in SEO and writes articles about latest emerging technologies.
Arif Khoja on FacebookArif Khoja on GoogleArif Khoja on InstagramArif Khoja on LinkedinArif Khoja on Twitter

Leave a Reply

%d bloggers like this: