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

Bootstrapping an Angular application

Similar to AngularJS, before our application gets rendered, it goes through the bootstrap process. In Angular, we can bootstrap an application in different ways, depending on the used platform (for instance, web, NativeScript, and with JIT or AOT compilation enabled). Let's take a look at a simple example, of how we can bootstrap a web app, in order to get a better understanding of how the Angular modules can be used in the process:

import {NgModule} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserModule} from '@angular/platform-browser';

import {AppComponent} from './app.component';

@NgModule({
  imports: [BrowserModule],
  bootstrap: [AppComponent],
  declarations: [AppComponent],
})
export class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

With the @NgModule decorator in the preceding example, we declare AppModule and we also import BrowserModule. Note that this time, we provide a value to the bootstrap property, where we explicitly declare that we want AppComponent to be used for bootstrapping our application.

On the last line of the file, we invoke the bootstrapModule method of the object returned by the invocation of platformBrowserDynamic with the AppModule argument.

In recap, the modules in Angular have an important role: they not only group the building blocks of our application logically but also provide a way we can achieve encapsulation. Last, but not least, NgModules are heavily used in the bootstrap process of the application.

主站蜘蛛池模板: 报价| 平度市| 鄂托克前旗| 聂荣县| 云南省| 台南市| 安福县| 东方市| 汶川县| 兴仁县| 开远市| 台中县| 托克逊县| 平潭县| 宝坻区| 涞水县| 新平| 思茅市| 惠水县| 昔阳县| 安化县| 衡南县| 龙口市| 永善县| 昌邑市| 鞍山市| 门源| 上犹县| 罗平县| 沙田区| 元谋县| 敦煌市| 武安市| 凉山| 息烽县| 凌海市| 彭泽县| 华安县| 平度市| 平遥县| 盈江县|