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.
The bootstrap property or key of the NgModule decorator specifies which component should be loaded by Angular when the app-level module loads. Angular reads the bootstrap metadata and loads the app-level component, called AppComponent .
A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process (application launch). Other entry components are loaded dynamically by other means, such as with the router. Angular loads a root AppComponent dynamically because it's listed by type in @NgModule. bootstrap .
Angular Material and Flex Layout are absolutely better than bootstrap. But that doesn't mean that you should not use bootstrap, but you may consider utilizing both the libraries.
From the docs:
You instantiate an Angular application by explicitly specifying a component to use as the root component for your application via the bootstrap() method.
So yes, it just starts the application.
bootstrap()
initializes an Angular application by executing (beside others)
APP_INITIALIZER
bootstrap
is the function which tells Angular2
system to render component over page as main component.
Also defines entity point of your application, by specifying root of your application.
//basically array will have dependencies of shared component which will instantiate only once.
bootstrap(MyComponent, [SharedService, OtherComponent, ROUTING_DIRECTIVES]);
But yes you should have mention that component selector over index.html
page like
<my-component></my-component>
If you compare this with Angular 1, you will find ng-app
directive which takes angular.module
name as an input like ng-app="myApp"
and make available those module component for that application OR angular.bootstrap
function to kick off application over the page.
Basically bootstrap()
in angular2 tell us the Entry point for the app very similer to ng-app
in angular 1.x, it creates angular zone for the whole app,In Angular 1.x we could use the ng-app
Directive, and give it a value such as ng-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
import {bootstrap} from 'angular2/platform/browser';
... Some Code stuff
bootstrap(AppComponent, [Common providers, or Global services, varibale etc]);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With