官术网_书友最值得收藏!

Bootstrapping

The starting point of our project is located within the src/main.ts file. This file is responsible for bootstrapping the Angular framework and starting our applications main module.

We can go ahead and bootstrap our Angular application by providing our main application module, AppModule.

In order to bootstrap an Angular module, we first need to create a platform. There are many ways for different platforms and environments to create a platform. If you'd like to create a browser platform, which is the default platform for browser environments, we need to import the platform factory function platformBrowserDynamic from the @angular/platform-browser-dynamic module. Simply by calling the platform factory function, we will receive an instance of the newly created platform. On the platform instance, we can then call the bootstrapModule function, passing our main application module as a parameter:

import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));

Let's take a closer look at the steps involved in the bootstrapping mechanism of Angular. We should try to understand how our root component is getting rendered in the right place by calling the bootstrapModule function on the platform instance:

  1. First, we call the bootstrapModule function on our platform instance, passing our main application module as a parameter
  2. Angular will examine our main application module metadata and find the AppComponent listed in the bootstrap property of the NgModule configuration
  3. By evaluating the metadata on the AppComponent, looking at the selector property, Angular will know where to render our root component
  4. The AppComponent is rendered as our root component into the host element found within the index.html file matching the CSS selector in the selector property on the component metadata
主站蜘蛛池模板: 城市| 互助| 东阿县| 南平市| 麻江县| 达日县| 阜康市| 麻阳| 竹北市| 家居| 天峻县| 通海县| 通渭县| 云安县| 南昌县| 尤溪县| 洮南市| 开鲁县| 绥德县| 仪陇县| 聂荣县| 高州市| 洪洞县| 台山市| 任丘市| 遵义市| 湖北省| 灵丘县| 个旧市| 阳谷县| 灵台县| 根河市| 长垣县| 开远市| 陵水| 涪陵区| 三江| 万全县| 铁岭县| 宣城市| 寻乌县|