forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoh-pt6.jade
141 lines (116 loc) · 4.4 KB
/
toh-pt6.jade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
extends ../../../ts/latest/tutorial/toh-pt6.jade
block includes
include ../_util-fns
- var _Http = 'BrowserClient';
- var _Angular_Http = 'Dart <code>BrowserClient</code>'
- var _httpUrl = 'https://pub.dartlang.org/packages/http'
- var _Angular_http_library = 'Dart <a href="' + _httpUrl + '"><b>http</b></a> package'
- var _HTTP_PROVIDERS = 'BrowserClient'
- var _JSON_stringify = 'JSON.encode'
block start-server-and-watch
:marked
### Keep the app compiling and running
Open a terminal/console window.
Start the Dart compiler, watch for changes, and start our server by entering the command:
code-example(language="bash").
pub serve
block http-library
:marked
We'll be using the !{_Angular_http_library}'s
`BrowserClient` class to communicate with a server.
### Pubspec updates
We need to add a package dependency for the !{_Angular_http_library}.
We also need to add a `resolved_identifiers` entry, to inform the [angular2
transformer][ng2x] that we'll be using `BrowserClient`. (For an explanation of why
this extra configuration is needed, see the [HTTP client chapter][guide-http].) We'll
also need to use `Client` from http, so let's add that now as well.
Update `pubspec.yaml` to look like this (additions are highlighted):
[guide-http]: ../guide/server-communication.html#!#http-providers
[ng2x]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer
- var stylePattern = { pnk: /(http.*|resolved_identifiers:|Browser.*|Client.*)/gm };
+makeExcerpt('pubspec.yaml', 'additions', null, stylePattern)
block http-providers
:marked
Before our app can use `#{_Http}`, we have to register it as a service provider.
block backend
:marked
We want to replace `BrowserClient`, the service that talks to the remote server,
with the in-memory web API service.
Our in-memory web API service, shown below, is implemented using the
`http` library `MockClient` class.
All `http` client implementations share a common `Client` interface, so
we'll have our app use the `Client` type so that we can freely switch between
implementations.
block dont-be-distracted-by-backend-subst
//- N/A
block get-heroes-details
:marked
To get the list of heroes, we first make an asynchronous call to
`http.get()`. Then we use the `_extractData` helper method to decode the
response payload (`body`).
block hero-detail-comp-extra-imports-and-vars
//- N/A
block hero-detail-comp-updates
:marked
### Edit in the *HeroDetailComponent*
We already have `HeroDetailComponent` for viewing details about a specific hero.
Supporting edit functionality is a natural extension of the detail view,
so we are able to reuse `HeroDetailComponent` with a few tweaks.
block hero-detail-comp-save-and-goback
//- N/A
block add-new-hero-via-detail-comp
//- N/A
block heroes-comp-directives
//- N/A
block heroes-comp-add
//- N/A
block review
//- Not showing animated gif due to differences between TS and Dart implementations.
block filetree
.filetree
.file angular2_tour_of_heroes
.children
.file lib
.children
.file app_component.dart
.file app_component.css
.file dashboard_component.css
.file dashboard_component.html
.file dashboard_component.dart
.file hero.dart
.file hero_detail_component.css
.file hero_detail_component.html
.file hero_detail_component.dart
.file hero_service.dart
.file heroes_component.css
.file heroes_component.html
.file heroes_component.dart
.file main.dart
.file in_memory_data_service.dart (new)
.file web
.children
.file main.dart
.file index.html
.file sample.css (new)
.file styles.css
.file pubspec.yaml
block file-summary
+makeTabs(
`toh-6/dart/lib/hero.dart,
toh-6/dart/lib/hero_detail_component.dart,
toh-6/dart/lib/hero_detail_component.html,
toh-6/dart/lib/hero_service.dart,
toh-6/dart/lib/heroes_component.dart,
toh-6/dart/web/index.html,
toh-6/dart/web/main.dart,
toh-6/dart/web/sample.css`,
`,,,,,,final,`,
`lib/hero.dart,
lib/hero_detail_component.dart,
lib/hero_detail_component.html,
lib/hero_service.dart,
lib/heroes_component.dart,
web/index.html,
web/main.dart,
web/sample.css`)
+makeExample('pubspec.yaml')