I’m very new to frontend frameworks and I am learning Angular 2. In the tutorial, it tells you to include the line bootstrap(AppComponent)
. What does this bootstrap function do? Is it simply what starts the app? I’m guessing it has nothing to do with the twitter-bootstrap UI framework.
5
Answers
bootstrap
is the function which tellsAngular2
system to render component over page as main component.Also defines entity point of your application, by specifying root of your application.
But yes you should have mention that component selector over
index.html
page likeIf you compare this with Angular 1, you will find
ng-app
directive which takesangular.module
name as an input likeng-app="myApp"
and make available those module component for that application ORangular.bootstrap
function to kick off application over the page.From the docs:
So yes, it just starts the application.
bootstrap()
initializes an Angular application by executing (beside others)APP_INITIALIZER
Basically
bootstrap()
in angular2 tell us the Entry point for the app very similer tong-app
in angular 1.x, it creates angular zone for the whole app,In Angular 1.x we could use theng-app
Directive, and give it a value such asng-app="myApp"
, or use the angular.bootstrap method which allows for asynchronous bootstrapping.The place we need to fetch the bootstrap method is angular2/platform/browser
also we can inject GlobalServices, variables which we are going to use in the whole app at the time of bootstraping our app,
by doing so we dont nees to imports those again and again in our components.
And now in Angular5:
Further reading: