AngularJS Bootstrap Process includes from AngularJS initialization to compilation process. AngularJS initialization can be done in two ways, automatic initialization and manual initialization.
In automatic initialization, AngularJS initializes automatically upon DOMContentLoaded event or when the angular.js script is read if at that time document.readyState is set to 'complete'. At this point Angular looks for the ng-app directive which is root of the AngularJS compilation process. If the ngApp directive is found then Angular will:
<!DOCTYPE html> <html> <head> <!-- www.techstrikers.com --> <title>Automatic Initialization</title> <script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script> <script> var app = angular.module('automaticInitialization', []) app.controller('autoInitController', ['$scope', function($scope) { $scope.url = "www.techstrikers.com" }]); </script> </head> <body style="background-color:#DDE4E9;" ng-app="automaticInitialization"> <fieldset style="background-color:#DDE4E9;"> <legend>AngulerJS Automatic Initialization Example</legend> <div ng-controller="autoInitController"> <p style="font-family:Arial;color:red;background:steelblue;padding:3px;width:350px;">{{url}}</p> </fieldset> </body> </html>See Live Example
Sometimes you may need to manual Initialize AngularJS in order to have more control over the initialization precess. You can do that by calling angular.bootstrap()
function inside angular.element(document).ready() function.
The angular.bootstrap()
function takes two parameters, the document and module name injector as the second parameter to the angular.bootstrap function.
<!DOCTYPE html> <html> <head> <title>Manual Initialization Using Bootstrap</title> <script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script> <script> var app = angular.module('manualInitialization', []) app.controller('manualInitController', ['$scope', function($scope) { $scope.url = "www.techstrikers.com" }]); angular.element(document).ready(function() { angular.bootstrap(document, ['manualInitialization']); }); </script> </head> <body style="background-color:#DDE4E9;"> <fieldset style="background-color:#DDE4E9;"> <legend>AngulerJS Manual Initialization Using Bootstrap Example</legend> <div ng-controller="manualInitController"> <p style="font-family:Arial;color:red;background:steelblue;padding:3px;width:350px;">{{url}}</p> </fieldset> </body> </html>See Live Example