8

刚刚开始使用 Angular 2。

  1. 角度 2 中的各种引导选项是什么?

  2. 为什么当我进行更改并刷新 index.html 时检索 HTML 标记需要很少的时间?

  3. 它们之间的差异

4

2 回答 2

8

有两种选择

  1. 动态引导

    • 编译器使用JIT(及时)。
    • 在浏览器中动态编译 ts 文件。
    • 这就是 index.html 检索标记花费很少时间的原因。
    • main.ts 包含以下内容

      import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
      import { AppModule }              from './app.module';
      
      platformBrowserDynamic().bootstrapModule(AppModule);
      
      1. 静态自举
    • 编译器使用AoT (Ahead of Time)。
    • ts文件编译成js文件,然后渲染到浏览器。
    • 通过这种方式,通过使它们轻量级,在那里创建了一组包含模块和工厂的 js 文件。
    • 主要用于移动设备和传统网络。
    • main.ts 包含以下内容

      import { platformBrowser } from '@angular/platform-browser';
      import { AppModuleNgFactory }              from '../aot/app/app.module.ngfactory';
      
      platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
      

差异 在此处输入图像描述

于 2016-12-08T23:00:36.713 回答
3

在 Angular 中有两种编译方式

  • JIT - 即时编译 AOT
  • 提前编译

关于 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
于 2018-07-25T05:20:52.857 回答