Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 562c629

Browse files
chalinkwalrath
authored andcommitted
docs(architecture): add Jade blocks for Dart, and other tweaks (#2990)
1 parent 5d7221c commit 562c629

File tree

2 files changed

+99
-93
lines changed

2 files changed

+99
-93
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ link-checker-results.txt
3535
/dist
3636
/public/docs/dart
3737
/public/docs/ts/_cache
38+
/public/docs/_examples/*/dart

public/docs/ts/latest/guide/architecture.jade

Lines changed: 98 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -48,115 +48,119 @@ figure
4848
## Modules
4949
figure
5050
img(src="/resources/images/devguide/architecture/module.png" alt="Component" align="left" style="width:240px; margin-left:-40px;margin-right:10px" )
51-
:marked
52-
Angular apps are modular and Angular has its own modularity system called _Angular modules_ or _NgModules_.
53-
54-
_Angular modules_ are a big deal.
55-
This page introduces modules; the [Angular modules](ngmodule.html) page covers them in depth.
5651

57-
<br class="l-clear-both"><br>
58-
:marked
59-
Every Angular app has at least one Angular module class, [the _root module_](appmodule.html "AppModule: the root module"),
60-
conventionally named `AppModule`.
52+
block angular-modules
53+
:marked
54+
Angular apps are modular and Angular has its own modularity system called _Angular modules_ or _NgModules_.
6155

62-
While the _root module_ may be the only module in a small application, most apps have many more
63-
_feature modules_, each a cohesive block of code dedicated to an application domain,
64-
a workflow, or a closely related set of capabilities.
56+
_Angular modules_ are a big deal.
57+
This page introduces modules; the [Angular modules](ngmodule.html) page covers them in depth.
6558

66-
An Angular module, whether a _root_ or _feature_, is a class with an `@NgModule` decorator.
67-
.l-sub-section
59+
<br class="l-clear-both"><br>
6860
:marked
69-
Decorators are functions that modify JavaScript classes.
70-
Angular has many decorators that attach metadata to classes so that it knows
71-
what those classes mean and how they should work.
72-
<a href="https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.x5c2ndtx0" target="_blank">
73-
Learn more</a> about decorators on the web.
74-
:marked
75-
`NgModule` is a decorator function that takes a single metadata object whose properties describe the module.
76-
The most important properties are:
77-
* `declarations` - the _view classes_ that belong to this module.
78-
Angular has three kinds of view classes: [components](#components), [directives](#directives), and [pipes](pipes.html).
61+
Every Angular app has at least one Angular module class, [the _root module_](appmodule.html "AppModule: the root module"),
62+
conventionally named `AppModule`.
63+
64+
While the _root module_ may be the only module in a small application, most apps have many more
65+
_feature modules_, each a cohesive block of code dedicated to an application domain,
66+
a workflow, or a closely related set of capabilities.
67+
68+
An Angular module, whether a _root_ or _feature_, is a class with an `@NgModule` decorator.
69+
.l-sub-section
70+
:marked
71+
Decorators are functions that modify JavaScript classes.
72+
Angular has many decorators that attach metadata to classes so that it knows
73+
what those classes mean and how they should work.
74+
<a href="https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.x5c2ndtx0" target="_blank">
75+
Learn more</a> about decorators on the web.
76+
:marked
77+
`NgModule` is a decorator function that takes a single metadata object whose properties describe the module.
78+
The most important properties are:
79+
* `declarations` - the _view classes_ that belong to this module.
80+
Angular has three kinds of view classes: [components](#components), [directives](#directives), and [pipes](pipes.html).
7981

80-
* `exports` - the subset of declarations that should be visible and usable in the component [templates](#templates) of other modules.
82+
* `exports` - the subset of declarations that should be visible and usable in the component [templates](#templates) of other modules.
8183

82-
* `imports` - other modules whose exported classes are needed by component templates declared in _this_ module.
84+
* `imports` - other modules whose exported classes are needed by component templates declared in _this_ module.
8385

84-
* `providers` - creators of [services](#services) that this module contributes to
85-
the global collection of services; they become accessible in all parts of the app.
86+
* `providers` - creators of [services](#services) that this module contributes to
87+
the global collection of services; they become accessible in all parts of the app.
8688

87-
* `bootstrap` - the main application view, called the _root component_,
88-
that hosts all other app views. Only the _root module_ should set this `bootstrap` property.
89+
* `bootstrap` - the main application view, called the _root component_,
90+
that hosts all other app views. Only the _root module_ should set this `bootstrap` property.
8991

90-
Here's a simple root module:
91-
+makeExample('app/mini-app.ts', 'module', 'app/app.module.ts')(format='.')
92+
Here's a simple root module:
93+
+makeExample('app/mini-app.ts', 'module', 'app/app.module.ts')(format='.')
9294

93-
.l-sub-section
95+
.l-sub-section
96+
:marked
97+
The `export` of `AppComponent` is just to show how to export; it isn't actually necessary in this example. A root module has no reason to _export_ anything because other components don't need to _import_ the root module.
9498
:marked
95-
The `export` of `AppComponent` is just to show how to export; it isn't actually necessary in this example. A root module has no reason to _export_ anything because other components don't need to _import_ the root module.
96-
:marked
97-
Launch an application by _bootstrapping_ its root module.
98-
During development you're likely to bootstrap the `AppModule` in a `main.ts` file like this one.
99-
100-
+makeExample('app/main.ts', '', 'app/main.ts')(format='.')
99+
Launch an application by _bootstrapping_ its root module.
100+
During development you're likely to bootstrap the `AppModule` in a `main.ts` file like this one.
101+
102+
+makeExample('app/main.ts', '', 'app/main.ts')(format='.')
101103

102-
:marked
103-
### Angular modules vs. JavaScript modules
104+
:marked
105+
### Angular modules vs. JavaScript modules
104106

105-
The Angular module &mdash; a class decorated with `@NgModule` &mdash; is a fundamental feature of Angular.
107+
The Angular module &mdash; a class decorated with `@NgModule` &mdash; is a fundamental feature of Angular.
106108

107-
JavaScript also has its own module system for managing collections of JavaScript objects.
108-
It's completely different and unrelated to the Angular module system.
109-
110-
In JavaScript each _file_ is a module and all objects defined in the file belong to that module.
111-
The module declares some objects to be public by marking them with the `export` key word.
112-
Other JavaScript modules use *import statements* to access public objects from other modules.
109+
JavaScript also has its own module system for managing collections of JavaScript objects.
110+
It's completely different and unrelated to the Angular module system.
111+
112+
In JavaScript each _file_ is a module and all objects defined in the file belong to that module.
113+
The module declares some objects to be public by marking them with the `export` key word.
114+
Other JavaScript modules use *import statements* to access public objects from other modules.
113115

114-
+makeExample('app/app.module.ts', 'imports', '')(format='.')
115-
+makeExample('app/app.module.ts', 'export', '')(format='.')
116-
117-
.l-sub-section
116+
+makeExample('app/app.module.ts', 'imports', '')(format='.')
117+
+makeExample('app/app.module.ts', 'export', '')(format='.')
118+
119+
.l-sub-section
120+
:marked
121+
<a href="http://exploringjs.com/es6/ch_modules.html" target="_blank">Learn more about the JavaScript module system on the web.</a>
118122
:marked
119-
<a href="http://exploringjs.com/es6/ch_modules.html" target="_blank">Learn more about the JavaScript module system on the web.</a>
120-
:marked
121-
These are two different and _complementary_ module systems. Use them both to write your apps.
123+
These are two different and _complementary_ module systems. Use them both to write your apps.
122124

125+
:marked
123126
### Angular libraries
124127

125128
figure
126129
img(src="/resources/images/devguide/architecture/library-module.png" alt="Component" align="left" style="width:240px; margin-left:-40px;margin-right:10px" )
127130

128-
:marked
129-
Angular ships as a collection of JavaScript modules. You can think of them as library modules.
130-
131-
Each Angular library name begins with the `!{_at_angular}` prefix.
132-
133-
You install them with the **npm** package manager and import parts of them with JavaScript `import` statements.
134-
<br class="l-clear-both"><br>
135-
:marked
136-
For example, import Angular's `Component` decorator from the `@angular/core` library like this:
137-
+makeExample('app/app.component.ts', 'import', '')(format='.')
138-
:marked
139-
You also import Angular _modules_ from Angular _libraries_ using JavaScript import statements:
140-
+makeExample('app/mini-app.ts', 'import-browser-module', '')(format='.')
141-
:marked
142-
In the example of the simple root module above, the application module needs material from within that `BrowserModule`. To access that material, add it to the `@NgModule` metadata `imports` like this.
143-
+makeExample('app/mini-app.ts', 'ngmodule-imports', '')(format='.')
144-
:marked
145-
In this way you're using both the Angular and JavaScript module systems _together_.
131+
block angular-libraries
132+
:marked
133+
Angular ships as a collection of JavaScript modules. You can think of them as library modules.
146134

147-
It's easy to confuse the two systems because they share the common vocabulary of "imports" and "exports".
148-
Hang in there. The confusion yields to clarity with time and experience.
135+
Each Angular library name begins with the `!{_at_angular}` prefix.
136+
137+
You install them with the **npm** package manager and import parts of them with JavaScript `import` statements.
138+
<br class="l-clear-both"><br>
149139

150-
.l-sub-section
140+
For example, import Angular's `Component` decorator from the `@angular/core` library like this:
141+
+makeExample('app/app.component.ts', 'import', '')(format='.')
142+
:marked
143+
You also import Angular _modules_ from Angular _libraries_ using JavaScript import statements:
144+
+makeExample('app/mini-app.ts', 'import-browser-module', '')(format='.')
145+
:marked
146+
In the example of the simple root module above, the application module needs material from within that `BrowserModule`. To access that material, add it to the `@NgModule` metadata `imports` like this.
147+
+makeExample('app/mini-app.ts', 'ngmodule-imports', '')(format='.')
151148
:marked
152-
Learn more from the [Angular modules](ngmodule.html) page.
149+
In this way you're using both the Angular and JavaScript module systems _together_.
150+
151+
It's easy to confuse the two systems because they share the common vocabulary of "imports" and "exports".
152+
Hang in there. The confusion yields to clarity with time and experience.
153+
154+
.l-sub-section
155+
:marked
156+
Learn more from the [Angular modules](ngmodule.html) page.
153157

154158
.l-hr
155159

156-
.l-main-section
160+
.l-main-section#components
157161
:marked
158-
<a id="components"></a>
159162
## Components
163+
160164
figure
161165
img(src="/resources/images/devguide/architecture/hero-component.png" alt="Component" align="left" style="width:200px; margin-left:-40px;margin-right:10px" )
162166

@@ -169,7 +173,6 @@ figure
169173
* The list of heroes.
170174
* The hero editor.
171175

172-
173176
You define a component's application logic&mdash;what it does to support the view&mdash;inside a class.
174177
The class interacts with the view through an API of properties and methods.
175178

@@ -253,7 +256,7 @@ block ts-decorator
253256
Here are a few of the possible `@Component` configuration options:
254257

255258
:marked
256-
- `moduleId`: sets the source of the base address (`module.id`) for module-relative URLs such as the `templateUrl`.
259+
<ul if-docs="ts"><li>`moduleId`: sets the source of the base address (`module.id`) for module-relative URLs such as the `templateUrl`.</ul>
257260

258261
- `selector`: CSS selector that tells Angular to create and insert an instance of this component
259262
where it finds a `<hero-list>` tag in *parent* HTML.
@@ -262,6 +265,9 @@ block ts-decorator
262265

263266
- `templateUrl`: module-relative address of this component's HTML template, shown [above](#templates).
264267

268+
block dart-directives
269+
270+
:marked
265271
- `providers`: !{_array} of **dependency injection providers** for services that the component requires.
266272
This is one way to tell Angular that the component's constructor requires a `HeroService`
267273
so it can get the list of heroes to display.
@@ -305,7 +311,7 @@ figure
305311

306312
:marked
307313
* The `{{hero.name}}` [*interpolation*](displaying-data.html#interpolation)
308-
displays the component's `hero.name` property value within the `<li>` tags.
314+
displays the component's `hero.name` property value within the `<li>` element.
309315

310316
* The `[hero]` [*property binding*](template-syntax.html#property-binding) passes the value of `selectedHero` from
311317
the parent `HeroListComponent` to the `hero` property of the child `HeroDetailComponent`.
@@ -349,12 +355,10 @@ figure
349355
Angular templates are *dynamic*. When Angular renders them, it transforms the DOM
350356
according to the instructions given by **directives**.
351357

352-
A directive is a class with directive metadata. In !{_Lang}, apply the `@Directive` !{_decorator}
353-
to attach metadata to the class.
354-
<br class="l-clear-both">
355-
:marked
358+
A directive is a class with a `@Directive` !{_decorator}.
356359
A component is a *directive-with-a-template*;
357360
a `@Component` !{_decorator} is actually a `@Directive` !{_decorator} extended with template-oriented features.
361+
<br class="l-clear-both">
358362

359363
.l-sub-section
360364
:marked
@@ -377,7 +381,6 @@ figure
377381
* [`*ngIf`](displaying-data.html#ngIf) includes the `HeroDetail` component only if a selected hero exists.
378382

379383
block dart-bool
380-
//- N/A
381384

382385
:marked
383386
**Attribute** directives alter the appearance or behavior of an existing element.
@@ -491,17 +494,19 @@ figure
491494
In brief, you must have previously registered a **provider** of the `HeroService` with the injector.
492495
A provider is something that can create or return a service, typically the service class itself.
493496

494-
You can register providers in modules or in components.
495-
496-
In general, add providers to the [root module](#module) so that
497-
the same instance of a service is available everywhere.
497+
block registering-providers
498+
:marked
499+
You can register providers in modules or in components.
500+
501+
In general, add providers to the [root module](#module) so that
502+
the same instance of a service is available everywhere.
498503

499-
+makeExample('app/app.module.ts', 'providers', 'app/app.module.ts (module providers)')(format='.')
504+
+makeExcerpt('app/app.module.ts (module providers)', 'providers')
500505

501506
:marked
502507
Alternatively, register at a component level in the `providers` property of the `@Component` metadata:
503508

504-
+makeExample('app/hero-list.component.ts', 'providers', 'app/hero-list.component.ts (component providers)')(format='.')
509+
+makeExcerpt('app/hero-list.component.ts (component providers)', 'providers')
505510

506511
:marked
507512
Registering at a component level means you get a new instance of the

0 commit comments

Comments
 (0)