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

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
主站蜘蛛池模板: 紫云| 仙居县| 南平市| 墨脱县| 广宗县| 孝义市| 梁平县| 普安县| 珠海市| 封开县| 冕宁县| 渑池县| 肥西县| 晋宁县| 射阳县| 教育| 勐海县| 和林格尔县| 馆陶县| 公安县| 奇台县| 上蔡县| 广州市| 台南市| 淮安市| 五华县| 贵南县| 隆尧县| 买车| 上林县| 平罗县| 顺平县| 高邮市| 溧阳市| 团风县| 榆林市| 赞皇县| 博湖县| 闽侯县| 洪泽县| 五寨县|