- Switching to Angular(Third Edition)
- Minko Gechev
- 220字
- 2021-07-02 15:23:33
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.
- Android Wearable Programming
- Visual C++程序設(shè)計(jì)教程
- GraphQL學(xué)習(xí)指南
- PHP基礎(chǔ)案例教程
- Machine Learning with R Cookbook(Second Edition)
- Learning Bayesian Models with R
- Servlet/JSP深入詳解
- 精通網(wǎng)絡(luò)視頻核心開發(fā)技術(shù)
- Modern C++ Programming Cookbook
- Swift語言實(shí)戰(zhàn)晉級
- 零基礎(chǔ)學(xué)C語言(第4版)
- 貫通Tomcat開發(fā)
- Python一行流:像專家一樣寫代碼
- Java核心編程
- SCRATCH編程課:我的游戲我做主