@@ -4,10 +4,7 @@ include ../_util-fns
4
4
## Setup to develop locally
5
5
Follow the [setup](../guide/setup.html) instructions for creating a new project
6
6
named <ngio-ex path="angular-tour-of-heroes"></ngio-ex>.
7
- <!-- CF: TO DO: Ward commented: if you only followed the current setup instructions, there would be many more files.
8
- I just added a section to the Setup guide for deleting non-essential files. We should refer to that too.
9
- See #3079 which will merge soon. The link to it would be:
10
- [_Deleting non-essential files_](../guide/setup.html#non-essential "Setup: Deleting non-essential files") -->
7
+
11
8
The file structure should look like this:
12
9
13
10
.filetree
@@ -24,7 +21,7 @@ include ../_util-fns
24
21
.file styles.css
25
22
.file systemjs.config.js
26
23
.file tsconfig.json
27
- .file node_modules ...
24
+ .file node_modules ...
28
25
.file package.json
29
26
:marked
30
27
When you're done with this page, the app should look like this <live-example></live-example>.
@@ -40,7 +37,7 @@ code-example(language="sh" class="code-shell").
40
37
:marked
41
38
This command runs the TypeScript compiler in "watch mode", recompiling automatically when the code changes.
42
39
The command simultaneously launches the app in a browser and refreshes the browser when the code changes.
43
-
40
+
44
41
You can keep building the Tour of Heroes without pausing to recompile or refresh the browser.
45
42
46
43
.l-main-section
@@ -52,7 +49,7 @@ code-example(language="sh" class="code-shell").
52
49
+ makeExample('toh-1/ts/app/app.component.1.ts' , 'app-component-1' , 'app.component.ts (AppComponent class)' )( format ="." )
53
50
54
51
:marked
55
- Now update the template in the `@Component` decoration with data bindings to these new properties.
52
+ Now update the template in the `@Component` decorator with data bindings to these new properties.
56
53
57
54
+ makeExample('toh-1/ts/app/app.component.1.ts' , 'show-hero' , 'app.component.ts (@Component)' )( format ='.' )
58
55
@@ -80,7 +77,7 @@ code-example(language="sh" class="code-shell").
80
77
81
78
:marked
82
79
In the `Hero` class, refactor the component's `hero` property to be of type `Hero`,
83
- then initialize it with an id of `1` and the name `Windstorm`.
80
+ then initialize it with an `id` of `1` and the name `Windstorm`.
84
81
85
82
+ makeExample('toh-1/ts/src/app/app.component.ts' , 'hero-property-1' , 'src/app/app.component.ts (hero property)' )( format ="." )
86
83
@@ -98,8 +95,8 @@ code-example(language="sh" class="code-shell").
98
95
add a `<div>` for the hero's `id` property and another `<div>` for the hero's `name`.
99
96
To keep the template readable, place each `<div>` on its own line.
100
97
101
- The backticks around the component template let you put the `<h1>`, `<h2>`, and `<div>` elements on their own lines,
102
- thanks to the <i>template literals</i> feature in ES2015 and TypeScript. For more information, see
98
+ The backticks around the component template let you put the `<h1>`, `<h2>`, and `<div>` elements on their own lines,
99
+ thanks to the <i>template literals</i> feature in ES2015 and TypeScript. For more information, see
103
100
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" target="_blank" title="template literal">Template literals</a>.
104
101
105
102
@@ -122,13 +119,13 @@ code-example(language="sh" class="code-shell").
122
119
123
120
:marked
124
121
`[(ngModel)]` is the Angular syntax to bind the `hero.name` property
125
- to the textbox.
122
+ to the textbox.
126
123
Data flow _in both directions_: from the property to the textbox;
127
124
and from the textbox back to the property.
128
125
129
126
Unfortunately, immediately after this change, the application breaks.
130
127
If you looked in the browser console, you'd see Angular complaining that
131
- " ' ngModel' ... isn't a known property of ' input' ."
128
+ "` ngModel` ... isn't a known property of ` input` ."
132
129
133
130
Although `NgModel` is a valid Angular directive, it isn't available by default.
134
131
It belongs to the optional `FormsModule`.
@@ -137,18 +134,18 @@ code-example(language="sh" class="code-shell").
137
134
### Import the _FormsModule_
138
135
139
136
Open the `app.module.ts` file and import the `FormsModule` symbol from the `@angular/forms` library.
140
- Then add the `FormsModule` to the `NgModule` metadata's `imports` array, which contains the list
137
+ Then add the `FormsModule` to the `@ NgModule` metadata's `imports` array, which contains the list
141
138
of external modules that the app uses.
142
-
139
+
143
140
The updated `AppModule` looks like this:
144
- + makeExample('toh-1/ts/app/app.module.ts' , '' , 'app.module.ts (FormsModule import)' )
141
+ + makeExample('toh-1/ts/src/ app/app.module.ts' , '' , 'app.module.ts (FormsModule import)' )
145
142
146
143
.l-sub-section
147
144
:marked
148
145
Read more about `FormsModule` and `ngModel` in the
149
- [_Two -way data binding with ngModel_ ](../guide/forms.html#ngModel) section of the
146
+ [Two -way data binding with ngModel ](../guide/forms.html#ngModel) section of the
150
147
[Forms](../guide/forms.html) guide and the
151
- [_Two -way binding with NgModel_ ](../guide/template-syntax.html#ngModel) section of the
148
+ [Two -way binding with NgModel ](../guide/template-syntax.html#ngModel) section of the
152
149
[Template Syntax](../guide/template-syntax.html) guide.
153
150
154
151
:marked
@@ -171,7 +168,7 @@ code-example(language="sh" class="code-shell").
171
168
172
169
Here's the complete `app.component.ts` as it stands now:
173
170
174
- + makeExample('toh-1/ts/src/app/app.component.ts' , 'pt1 ' , 'src/app/app.component.ts' )
171
+ + makeExample('toh-1/ts/src/app/app.component.ts' , '' , 'src/app/app.component.ts' )
175
172
176
173
177
174
.l-main-section
0 commit comments