You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Copy file name to clipboardExpand all lines: public/docs/ts/latest/tutorial/toh-pt6.jade
+56-44Lines changed: 56 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -1,51 +1,22 @@
1
1
include../_util-fns
2
2
3
3
:marked
4
-
# Http
4
+
# Getting and Saving Data with HTTP
5
5
6
-
Our application has become a huge success and our stakeholders have expanded the vision to include integration with a hero api.
6
+
Our stakeholders appreciate our progress.
7
+
Now they want to get the hero data from a server, let users add, edit, and delete heroes,
8
+
and save these changes back to the server.
7
9
8
-
The current solution limits us to a fixed set of heroes, but integration with a web server api will make our application much more flexible. We will also be able to add, edit and delete heroes.
9
-
10
-
In this chapter we will connect our Angular 2 services to make http calls to our new api.
10
+
In this chapter we teach our application to make the corresponding http calls to a remote server's web api.
11
11
:marked
12
12
[Run the live example](/resources/live-examples/toh-6/ts/plnkr.html).
13
13
14
14
.l-main-section
15
15
:marked
16
16
## Where We Left Off
17
-
Before we continue with our Tour of Heroes, let’s verify that we have the following structure after adding our hero service
18
-
and hero detail component. If not, we’ll need to go back and follow the previous chapters.
17
+
In the [previous chapter](toh-pt5.html), we learned to navigate between the dashboard and the fixed heroes list, editing a selected hero along the way.
18
+
That's our starting point for this chapter.
19
19
20
-
.filetree
21
-
.file angular2-tour-of-heroes
22
-
.children
23
-
.file app
24
-
.children
25
-
.file app.component.ts
26
-
.file app.component.css
27
-
.file dashboard.component.css
28
-
.file dashboard.component.html
29
-
.file dashboard.component.ts
30
-
.file hero.ts
31
-
.file hero-detail.component.css
32
-
.file hero-detail.component.html
33
-
.file hero-detail.component.ts
34
-
.file hero.service.ts
35
-
.file heroes.component.css
36
-
.file heroes.component.html
37
-
.file heroes.component.ts
38
-
.file main.ts
39
-
.file mock-heroes.ts
40
-
.file node_modules ...
41
-
.file typings ...
42
-
.file index.html
43
-
.file package.json
44
-
.file styles.css
45
-
.file systemjs.config.json
46
-
.file tsconfig.json
47
-
.file typings.json
48
-
:marked
49
20
### Keep the app transpiling and running
50
21
Open a terminal/console window and enter the following command to
51
22
start the TypeScript compiler, start the server, and watch for changes:
Loading heroes using `Http` required no changes outside of `HeroService`, but we added a few new features as well. In the following section we will update our components to use our new methods to add, edit and delete heroes.
217
+
Loading heroes using `Http` required no changes outside of `HeroService`, but we added a few new features as well.
218
+
In the following section we will update our components to use our new methods to add, edit and delete heroes.
247
219
248
-
### Add/Edit
220
+
### Add/Edit in the *HeroDetailComponent*
249
221
We already have `HeroDetailComponent` for viewing details about a specific hero. Add and Edit are natural extensions of the detail view, so we are able to reuse `DetailHeroComponent` with a few tweaks. The original component was created to render existing data, but to add new data we have to initialize the `hero` property to an empty `Hero` object.
The `emit` "handshake" between `HeroDetailComponent` and `HeroesComponent` is an example of component to component communication. This is a topic for another day, but we have detailed information in our <a href="/docs/ts/latest/cookbook/component-communication.html#!#child-to-parent">Component Interaction Cookbook</a>
268
240
269
241
:marked
270
-
Here is `HeroDetailComponent` with the added save button.
242
+
Here is `HeroDetailComponent` with its new save button.
271
243
272
244
figure.image-display
273
245
img(src='/resources/images/devguide/toh/hero-details-save-button.png'alt="Hero Details With Save Button")
274
246
275
247
:marked
276
-
### Delete
248
+
### Add/Delete in the *HeroesComponent*
249
+
250
+
The user can *add* a new hero by clicking a button and entering a name.
251
+
252
+
When the user clicks the *Add New Hero* button, we display the `HeroDetailComponent`.
253
+
We aren't navigating to the component so it won't receive a hero `id`;
254
+
As we noted above, that is the component's cue to create and present an empty hero.
255
+
256
+
Add the following HTML to the `heroes.component.html`, just below the hero list (the `*ngFor`).
The user can *delete* an existing hero by clicking a delete button next to the hero's name.
277
260
278
-
We have added the option to delete hereos from `HeroesComponent`. `HeroService` will delete the hero, but we still have to filter out the deleted hero from the list to update the view.
261
+
Add the following HTML to the `heroes.component.html` right after the name in the repeated `<li>` tag:
0 commit comments