top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Which angular function is used to manually start up an angular application and How?

0 votes
779 views
Which angular function is used to manually start up an angular application and How?
posted Jan 24, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The starting up of angular application are of different methods ,

Manually starting up an angular application is shown below

angular.bootstrap(document, ['MyApp']);

This will work if you have your scripts loaded at the end of the page (instead of in the header).
Otherwise, the DOM will not be loaded at the time of bootrsaping the app

angular.bootstrap(angular.element("body")[0], ['MyApp']);

The same as before, using body as the root of the application. It uses a selector that is not available in jqLite, so you need to have full jQuery included in the app.

angular.element(document).ready(function() {
  angular.bootstrap(document);
});

The above code waits for the DOM to be loaded, so it will work even if you include your scripts in the header.
This is basically the same as jQuery code

$(document).ready

, but using jqLite's angular.element.

angular.element(document).ready(function() {
  angular.bootstrap(document, ['MyApp']);
});

In the above code, modules are being passed to the bootstrap function, most likely you will need to declare your main module, unless your app consists only on controllers in the global namespace.

answer Feb 7, 2017 by Arun Angadi
...