刚刚开始使用 Angular 2。
角度 2 中的各种引导选项是什么?
为什么当我进行更改并刷新 index.html 时检索 HTML 标记需要很少的时间?
它们之间的差异
刚刚开始使用 Angular 2。
角度 2 中的各种引导选项是什么?
为什么当我进行更改并刷新 index.html 时检索 HTML 标记需要很少的时间?
它们之间的差异
有两种选择
动态引导
main.ts 包含以下内容
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
main.ts 包含以下内容
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
在 Angular 中有两种编译方式
关于 JIT 与 AOT 编译,我想补充四个主要区别
|----------------------------------------|---------------------------------------------|
| JIT | AOT |
|----------------------------------------|---------------------------------------------|
| JIT compilation as the name implies, | AOT compilation compiles the application at |
| compiles the application Just in Time | build time |
| in the browser at runtime | |
|----------------------------------------|---------------------------------------------|
|For JIT compilation the browser needs to| AOT compilation it does not have to |
|download the angular compiler | |
|----------------------------------------|---------------------------------------------|
|While the application is being JIT | With AOT, the application is precompiled |
|compiled in the browser, users have | so there no such wait |
|to wait | |
|----------------------------------------|---------------------------------------------|
|With JIT compilation, the template | With AOT compilation we will come to |
|binding errors are only know at runtime | now about them at build time. |
|----------------------------------------|---------------------------------------------|
默认情况下,以下2条命令使用JIT编译
ng build
ng serve
使用这些命令中的任何一个,我们都可以使用- -aot
选项来打开 AOT
ng build --aot
ngserve --aot
要为生产版本关闭 ACT,请将- - aot
选项设置为false
ng build -- prod --aot false