Angular Bootstrapping

Angular Bootstrapping

AngularJS Auto Bootstrapping :

Angular initializes / bootstraps automatically upon DOMm Content loaded 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. When the ng-app directive is found then Angular will:

Load the module associated with the directive.

Create the application injector.

Compile the DOM starting from the ng-app root element.

This process is called Auto-bootstrapping.

AngularJS – Manual 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.

<html>

<body>
<div ng-controller=”Ctrl”>Hello {{msg}}!</div>
<script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js”></script>
<script>
var app = angular.module(‘myApp’, []);
app.controller(‘Ctrl’, function($scope) {
$scope.msg = ‘Nik’;
});
//manual bootstrap process
angular.element(document).ready(function () { angular.bootstrap(document, [‘myApp’]); });
</script>
</body>

 

The bootstrap array

The application launches by bootstrapping the root AppModule, which is also referred to as an entryComponent. Among other things, the bootstrapping process creates the component(s) listed in the bootstrap array and inserts each one into the browser DOM.

Each bootstrapped component is the base of its own tree of components. Inserting a bootstrapped component usually triggers a cascade of component creations that fill out that tree.

While you can put more than one component tree on a host web page, most applications have only one component tree and bootstrap a single root component.

This one root component is usually called AppComponent and is in the root module’s bootstrap array.

 

IT Professionals, Web Developers, Web Programmers, IT students can Apply for the certification course to move ahead in their careers.

Angular 4 Tutorial IndexBack to Angular 4 Tutorial Main Page

Share this post
[social_warfare]
Angular NgModule Basics
Angular Feature Modules

Get industry recognized certification – Contact us

keyboard_arrow_up