@@ -20,7 +20,31 @@ include _util-fns
20
20
// #docregion a1
21
21
<a id =" A" ></a >
22
22
// #enddocregion a1
23
+ a#aot
23
24
.l-main-section
25
+ :marked
26
+ ## Ahead of Time (AOT) Compilation
27
+ .l-sub-section
28
+ :marked
29
+ Angular applications can be compiled by developers at build-time.
30
+ By compiling your application using the compiler-cli, `ngc`, you can boostrap directly
31
+ to a Module Factory, meaning you don't need to include the Angular compiler in your javascript bundle.
32
+ Ahead of Time compiled applications also benefit from decreased load time and increased performance.
33
+
34
+ .l-main-section
35
+ <a id =" angular-module" ></a >
36
+ :marked
37
+ ## Angular Module
38
+ .l-sub-section
39
+ :marked
40
+ Helps us organize an application into cohesive blocks of functionality.
41
+ An Angular module identifies the components, directives, and pipes that are used by the application
42
+ along with the list of external Angular modules that the application needs, such as `FormsModule`.
43
+
44
+ Every Angular application has an application root module class. By convention the class is
45
+ called `AppModule` and resides in a file named `app.component.ts`.
46
+
47
+ See the [Angular Module](/docs/ts/latest/guide/ngmodule.html) chapter for details and examples.
24
48
:marked
25
49
## Annotation
26
50
.l-sub-section
@@ -50,10 +74,10 @@ include _util-fns
50
74
## Barrel
51
75
.l-sub-section
52
76
:marked
53
- A barrel is a way to *rollup exports* from several modules into a single convenience module.
54
- The barrel itself is a module file that re-exports *selected* exports of other modules.
77
+ A barrel is a way to *rollup exports* from several ES2015 modules into a single convenience ES2015 module.
78
+ The barrel itself is an ES2015 module file that re-exports *selected* exports of other ES2015 modules.
55
79
56
- Imagine three modules in a `heroes` folder:
80
+ Imagine three ES2015 modules in a `heroes` folder:
57
81
code-example.
58
82
// heroes/hero.component.ts
59
83
export class HeroComponent {}
@@ -81,12 +105,17 @@ include _util-fns
81
105
import { Hero, HeroService } from '../heroes'; // index is implied
82
106
:marked
83
107
The Angular [scoped packages](#scoped-package) each have a barrel named `index`.
108
+
84
109
// #enddocregion b-c
85
110
:marked
86
111
That's why we can write this:
87
112
+ makeExcerpt('quickstart/ts/app/app.component.ts' , 'import' , '' )
88
113
// #docregion b-c
89
114
115
+ .alert.is-important
116
+ :marked
117
+ Note that you can often achieve this same goal using [Angular modules](#angular-module) instead.
118
+
90
119
:marked
91
120
## Binding
92
121
.l-sub-section
@@ -102,10 +131,9 @@ include _util-fns
102
131
## Bootstrap
103
132
.l-sub-section
104
133
:marked
105
- We launch an Angular application by "bootstrapping" it with the `bootstrap` method.
106
- The `bootstrap` method identifies an application's top level "root" [Component](#component)
107
- and optionally registers service [providers](#provider) with the
108
- [dependency injection system](#dependency-injection).
134
+ We launch an Angular application by "bootstrapping" it using the application root Angular module (`AppModule`).
135
+ The bootstraping identifies an application's top level "root" [Component](#component), which is the first
136
+ component that is loaded for the application. For more information see the [QuickStart](/docs/ts/latest/quickstart.html).
109
137
110
138
One can bootstrap multiple apps in the same `index.html`, each with its own top level root.
111
139
@@ -271,9 +299,7 @@ include _util-fns
271
299
Registering providers is a critical preparatory step.
272
300
273
301
Angular registers some of its own providers with every injector.
274
- We can register our own providers. Quite often the best time to register a `Provider`
275
- is when we [bootstrap](#bootstrap) the application.
276
- There are other opportunities to register as well.
302
+ We can register our own providers.
277
303
278
304
Learn more in the [Dependency Injection](/docs/ts/latest/guide/dependency-injection.html) chapter.
279
305
:marked
@@ -322,23 +348,17 @@ include _util-fns
322
348
The [official JavaScript language specification](https://en.wikipedia.org/wiki/ECMAScript).
323
349
324
350
The latest approved version of JavaScript is
325
- [ECMAScript 2015 ](http://www.ecma-international.org/ecma-262/6 .0/)
326
- (AKA "ES2015 " or "ES6 ") and many Angular 2 developers will write their applications
351
+ [ECMAScript 2016 ](http://www.ecma-international.org/ecma-262/7 .0/)
352
+ (AKA "ES2016 " or "ES7 ") and many Angular 2 developers will write their applications
327
353
either in this version of the language or a dialect that strives to be
328
354
compatible with it such as [TypeScript](#typesScript).
329
355
330
- Most modern browsers today only support the prior "ECMAScript 5" (AKA ES5) standard.
331
- Applications written in ES2015 or one of its dialects must be "[transpiled](#transpile)"
356
+ Most modern browsers today only support the much older "ECMAScript 5" (AKA ES5) standard.
357
+ Applications written in ES2016, ES2015 or one of their dialects must be "[transpiled](#transpile)"
332
358
to ES5 JavaScript.
333
359
334
360
Angular 2 developers may choose to write in ES5 directly.
335
- :marked
336
- ## ECMAScript 2015
337
- .l-sub-section
338
- :marked
339
- The latest released version of JavaScript,
340
- [ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/)
341
- (AKA "ES2015" or "ES6")
361
+
342
362
:marked
343
363
## ES2015
344
364
.l-sub-section
@@ -402,7 +422,16 @@ include _util-fns
402
422
403
423
<a id =" J" ></a >
404
424
425
+ a#jit
405
426
.l-main-section
427
+ :marked
428
+ ## Just in Time (JIT) Compilation
429
+ .l-sub-section
430
+ :marked
431
+ With Angular _Just in Time_ bootstrapping you compile your components and modules in the browser
432
+ and launch the application dynamically. This is a good choice during development.
433
+ Consider the [Ahead of Time](#aot) mode for production apps.
434
+
406
435
<a id =" K" ></a >
407
436
:marked
408
437
## kebab-case
@@ -450,6 +479,14 @@ include _util-fns
450
479
:marked
451
480
## Module
452
481
.l-sub-section
482
+
483
+ .alert.is-important
484
+ :marked
485
+ In Angular, there are two types of modules:
486
+ - [Angular modules](#angular-module).
487
+ See the [Angular Module](/docs/ts/latest/guide/ngmodule.html) chapter for details and examples.
488
+ - ES2015 modules as described in this section.
489
+
453
490
:marked
454
491
Angular apps are modular.
455
492
@@ -487,6 +524,17 @@ include _util-fns
487
524
<a id =" N" ></a >
488
525
<a id =" O" ></a >
489
526
.l-main-section
527
+ :marked
528
+ ## Observable
529
+ .l-sub-section
530
+ :marked
531
+ We can think of an observable as an array whose items arrive asynchronously over time.
532
+ Observables help us manage asynchronous data, such as data coming from a backend service.
533
+ Observables are used within Angular itself, including Angular's event system and its http client service.
534
+
535
+ To use observables, Angular uses a third-party library called Reactive Extensions (RxJS).
536
+ Observables are a proposed feature for ES 2016, the next version of JavaScript.
537
+
490
538
:marked
491
539
## Output
492
540
.l-sub-section
@@ -505,7 +553,7 @@ include _util-fns
505
553
.l-sub-section
506
554
:marked
507
555
The practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter.
508
- Class names are typically spelled in PascalCase. Examples include: `Person` and `Customer `.
556
+ Class names are typically spelled in PascalCase. Examples include: `Person` and `HeroDetailComponent `.
509
557
510
558
This form is also known as **upper camel case**, to distinguish it from **lower camel case** which we simply call [camelCase](#camelcase).
511
559
In this documentation, "PascalCase" means *upper camel case* and "camelCase" means *lower camel case*.
@@ -516,7 +564,7 @@ include _util-fns
516
564
:marked
517
565
An Angular pipe is a function that transforms input values to output values for
518
566
display in a [view](#view). We use the `#{atSym}Pipe` !{decorator}
519
- to associate the pipe function with a name. We then can use that
567
+ to associate the pipe function with a name. We can then use that
520
568
name in our HTML to declaratively transform values on screen.
521
569
522
570
Here's an example that uses the built-in `currency` pipe to display
@@ -543,6 +591,23 @@ include _util-fns
543
591
.l-main-section
544
592
<a id =" Q" ></a >
545
593
<a id =" R" ></a >
594
+ <a id =" reactive-forms" ></a >
595
+ :marked
596
+ ## Reactive Forms
597
+ .l-sub-section
598
+ :marked
599
+ A technique for building Angular forms through code in a component.
600
+ The alternate technique is [Template-Driven Forms](#template-driven-forms).
601
+
602
+ When building reactive forms:
603
+ - The "source of truth" is the component. The validation is defined using code in the component.
604
+ - Each control is explicitly created in the component class with `new FormControl()` or with `FormBuilder`.
605
+ - The template input elements do *not* use `ngModel`.
606
+ - The associated Angular directives are all prefixed with `Form` such as `FormGroup`, `FormControl`, and `FormControlName`.
607
+
608
+ Reactive forms are powerful, flexible, and great for more complex data entry form scenarios, such as dynamic generation
609
+ of form controls.
610
+
546
611
:marked
547
612
## Router
548
613
.l-sub-section
@@ -555,18 +620,32 @@ include _util-fns
555
620
The Angular [Component Router](/docs/ts/latest/guide/router.html) is a richly featured mechanism for configuring
556
621
and managing the entire view navigation process including the creation and destruction
557
622
of views.
623
+
624
+ In most cases, components becomes attached to a [router](#router) by means
625
+ of a `RouterConfig` that defines routes to views.
626
+
627
+ A [routing component's](#routing-component) template has a `RouterOutlet` element where it can display views produced by the router.
628
+
629
+ Other views in the application likely have anchor tags or buttons with `RouterLink` directives that users can click to navigate.
630
+
631
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more.
632
+
558
633
:marked
559
- ## Routing Component
634
+ ## RouterModule
560
635
.l-sub-section
561
636
:marked
562
- A [Component ](#component) with an attached router .
637
+ A separate [Angular module ](#angular-module) that provides the necessary service providers and directives for navigating through application views .
563
638
564
- In most cases, the component became attached to a [router](#router) by means
565
- of a `#{atSym}RouterConfig` #{decorator} that defined routes to views controlled by this component.
639
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more.
566
640
567
- The component's template has a `RouterOutlet` element where it can display views produced by the router.
641
+ <a id =" routing-component" ></a >
642
+ :marked
643
+ ## Routing Component
644
+ .l-sub-section
645
+ :marked
646
+ An Angular [Component](#component) with a RouterOutlet that displays views based on router navigations.
568
647
569
- It likely has anchor tags or buttons with `RouterLink` directives that users can click to navigate .
648
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more .
570
649
571
650
<a id =" S" ></a >
572
651
.l-main-section
@@ -587,6 +666,23 @@ include _util-fns
587
666
+ makeExcerpt('architecture/ts/app/app.component.ts' , 'import' , '' )
588
667
// #docregion n-s-2
589
668
669
+ :marked
670
+ ## Service
671
+ .l-sub-section
672
+ :marked
673
+ Components are great and all … but what do we do with data or logic that are not associated
674
+ with a specific view or that we want to share across components? We build services!
675
+
676
+ Applications often require services such as a hero data service or a logging service.
677
+ Our components depend on these services to do the heavy lifting.
678
+
679
+ A service is a class with a focused purpose.
680
+ We often create a service to implement features that are
681
+ independent from any specific view,
682
+ provide share data or logic across components, or encapsulate external interactions.
683
+
684
+ See the [Services](/docs/ts/latest/tutorial/toh-pt4.html) chapter of the tutorial to learn more.
685
+
590
686
:marked
591
687
## Structural Directive
592
688
.l-sub-section
@@ -597,6 +693,8 @@ include _util-fns
597
693
598
694
The `ngIf` "conditional element" directive and the `ngFor` "repeater" directive are
599
695
good examples in this category.
696
+
697
+ See the [Structural Directives](/docs/ts/latest/guide/structural-directives.html) chapter to learn more.
600
698
// #enddocregion n-s-2
601
699
602
700
// #docregion t1
@@ -612,11 +710,31 @@ include _util-fns
612
710
613
711
We write templates in a special [Template Syntax](/docs/ts/latest/guide/template-syntax.html).
614
712
713
+ <a id =" template-driven-forms" ></a >
714
+ :marked
715
+ ## Template-Driven Forms
716
+ .l-sub-section
717
+ :marked
718
+ A technique for building Angular forms using HTML forms and input elements in the view.
719
+ The alternate technique is [Reactive Forms](#reactive-forms).
720
+
721
+ When building template-driven forms:
722
+ - The "source of truth" is the template. The validation is defined using attributes on the individual input elements.
723
+ - [Two-way binding](#data-binding) with `ngModel` keeps the component model in synchronization with the user's entry into the input elements.
724
+ - Behind the scenes, Angular creates a new control for each input element that has a `name` attribute and
725
+ two-way binding set up.
726
+ - The associated Angular directives are all prefixed with `ng` such as `ngForm`, `ngModel`, and `ngModelGroup`.
727
+
728
+ Template-driven forms are convenient, quick, and simple and are a good choice for many basic data entry form scenarios.
729
+
730
+ Learn how to build template-driven forms
731
+ in the [Forms](/docs/ts/latest/guide/forms.html) chapter.
732
+
615
733
:marked
616
734
## Template Expression
617
735
.l-sub-section
618
736
:marked
619
- An expression in a JavaScript-like syntax that Angular evaluates within
737
+ An expression is a JavaScript-like syntax that Angular evaluates within
620
738
a [data binding](#data-binding). Learn how to write template expressions
621
739
in the [Template Syntax](/docs/ts/latest/guide/template-syntax.html#template-expressions) chapter.
622
740
0 commit comments