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

Commit f91a721

Browse files
docs(HTTP Client): edit copy
1 parent fdc1b04 commit f91a721

File tree

11 files changed

+366
-365
lines changed

11 files changed

+366
-365
lines changed

public/docs/_examples/server-communication/ts/app/app.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Component } from '@angular/core';
44

55
// #docregion import-rxjs
6-
// Add the RxJS Observable operators we need in this app.
6+
// Add the RxJS Observable operators.
77
import './rxjs-operators';
88
// #enddocregion import-rxjs
99

public/docs/_examples/server-communication/ts/app/hero-data.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { InMemoryDbService } from 'angular-in-memory-web-api';
33
export class HeroData implements InMemoryDbService {
44
createDb() {
55
let heroes = [
6-
{ id: '1', name: 'Windstorm' },
7-
{ id: '2', name: 'Bombasto' },
8-
{ id: '3', name: 'Magneta' },
9-
{ id: '4', name: 'Tornado' }
6+
{ id: 1, name: 'Windstorm' },
7+
{ id: 2, name: 'Bombasto' },
8+
{ id: 3, name: 'Magneta' },
9+
{ id: 4, name: 'Tornado' }
1010
];
1111
return {heroes};
1212
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"data": [
3-
{ "id": "1", "name": "Windstorm" },
4-
{ "id": "2", "name": "Bombasto" },
5-
{ "id": "3", "name": "Magneta" },
6-
{ "id": "4", "name": "Tornado" }
3+
{ "id": 1, "name": "Windstorm" },
4+
{ "id": 2, "name": "Bombasto" },
5+
{ "id": 3, "name": "Magneta" },
6+
{ "id": 4, "name": "Tornado" }
77
]
88
}

public/docs/_examples/server-communication/ts/app/rxjs-operators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// import 'rxjs/Rx'; // adds ALL RxJS statics & operators to Observable
33

44
// See node_module/rxjs/Rxjs.js
5-
// Import just the rxjs statics and operators we need for THIS app.
5+
// Import just the rxjs statics and operators needed for THIS app.
66

77
// Statics
88
import 'rxjs/add/observable/throw';

public/docs/_examples/server-communication/ts/app/toh/hero.service.promise.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ export class HeroService {
2222
}
2323

2424
addHero (name: string): Promise<Hero> {
25-
let body = JSON.stringify({ name });
2625
let headers = new Headers({ 'Content-Type': 'application/json' });
2726
let options = new RequestOptions({ headers: headers });
2827

29-
return this.http.post(this.heroesUrl, body, options)
28+
return this.http.post(this.heroesUrl, { name }, options)
3029
.toPromise()
3130
.then(this.extractData)
3231
.catch(this.handleError);
@@ -38,8 +37,8 @@ export class HeroService {
3837
}
3938

4039
private handleError (error: any) {
41-
// In a real world app, we might use a remote logging infrastructure
42-
// We'd also dig deeper into the error to get a better message
40+
// In a real world app, you might use a remote logging infrastructure
41+
// You'd also dig deeper into the error to get a better message
4342
let errMsg = (error.message) ? error.message :
4443
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
4544
console.error(errMsg); // log to console instead

public/docs/_examples/server-communication/ts/app/toh/hero.service.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ export class HeroService {
3434
// #docregion addhero, addhero-sig
3535
addHero (name: string): Observable<Hero> {
3636
// #enddocregion addhero-sig
37-
let body = JSON.stringify({ name });
3837
let headers = new Headers({ 'Content-Type': 'application/json' });
3938
let options = new RequestOptions({ headers: headers });
4039

41-
return this.http.post(this.heroesUrl, body, options)
40+
return this.http.post(this.heroesUrl, { name }, options)
4241
.map(this.extractData)
4342
.catch(this.handleError);
4443
}
@@ -53,8 +52,8 @@ export class HeroService {
5352

5453
// #docregion error-handling
5554
private handleError (error: any) {
56-
// In a real world app, we might use a remote logging infrastructure
57-
// We'd also dig deeper into the error to get a better message
55+
// In a real world app, you might use a remote logging infrastructure
56+
// You'd also dig deeper into the error to get a better message
5857
let errMsg = (error.message) ? error.message :
5958
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
6059
console.error(errMsg); // log to console instead
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* tslint:disable: member-ordering forin */
2+
// #docplaster
13
// #docregion
24
import { Component } from '@angular/core';
35
import { Observable } from 'rxjs/Observable';
@@ -8,33 +10,27 @@ import { Subject } from 'rxjs/Subject';
810
import { WikipediaService } from './wikipedia.service';
911

1012
@Component({
13+
moduleId: module.id,
1114
selector: 'my-wiki-smart',
12-
template: `
13-
<h1>Smarter Wikipedia Demo</h1>
14-
<p><i>Fetches when typing stops</i></p>
15-
16-
<input #term (keyup)="search(term.value)"/>
17-
18-
<ul>
19-
<li *ngFor="let item of items | async">{{item}}</li>
20-
</ul>
21-
`,
22-
providers: [WikipediaService]
15+
templateUrl: 'wiki.component.html',
16+
providers: [ WikipediaService ]
2317
})
2418
export class WikiSmartComponent {
25-
26-
constructor (private wikipediaService: WikipediaService) { }
19+
title = 'Smarter Wikipedia Demo';
20+
fetches = 'Fetches when typing stops';
21+
items: Observable<string[]>;
2722

2823
// #docregion subject
2924
private searchTermStream = new Subject<string>();
30-
3125
search(term: string) { this.searchTermStream.next(term); }
3226
// #enddocregion subject
3327

34-
// #docregion observable-operators
35-
items: Observable<string[]> = this.searchTermStream
36-
.debounceTime(300)
37-
.distinctUntilChanged()
38-
.switchMap((term: string) => this.wikipediaService.search(term));
39-
// #enddocregion observable-operators
28+
constructor (private wikipediaService: WikipediaService) {
29+
// #docregion observable-operators
30+
this.items = this.searchTermStream
31+
.debounceTime(300)
32+
.distinctUntilChanged()
33+
.switchMap((term: string) => this.wikipediaService.search(term));
34+
// #enddocregion observable-operators
35+
}
4036
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- #docregion -->
2+
<h1>{{title}}</h1>
3+
<p><i>{{fetches}}</i></p>
4+
5+
<!-- #docregion keyup -->
6+
<input #term (keyup)="search(term.value)"/>
7+
<!-- #enddocregion keyup -->
8+
9+
<ul>
10+
<li *ngFor="let item of items | async">{{item}}</li>
11+
</ul>

public/docs/_examples/server-communication/ts/app/wiki/wiki.component.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@ import { Observable } from 'rxjs/Observable';
55
import { WikipediaService } from './wikipedia.service';
66

77
@Component({
8+
moduleId: module.id,
89
selector: 'my-wiki',
9-
template: `
10-
<h1>Wikipedia Demo</h1>
11-
<p><i>Fetches after each keystroke</i></p>
12-
13-
<input #term (keyup)="search(term.value)"/>
14-
15-
<ul>
16-
<li *ngFor="let item of items | async">{{item}}</li>
17-
</ul>
18-
`,
19-
providers: [WikipediaService]
10+
templateUrl: 'wiki.component.html',
11+
providers: [ WikipediaService ]
2012
})
2113
export class WikiComponent {
14+
title = 'Wikipedia Demo';
15+
fetches = 'Fetches after each keystroke';
2216
items: Observable<string[]>;
2317

24-
constructor (private wikipediaService: WikipediaService) {}
25-
2618
search (term: string) {
2719
this.items = this.wikipediaService.search(term);
2820
}
21+
22+
constructor (private wikipediaService: WikipediaService) { }
2923
}

public/docs/ts/latest/guide/_data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
"server-communication": {
110110
"title": "HTTP Client",
111-
"intro": "Talk to a remote server with an HTTP Client."
111+
"intro": "Use an HTTP Client to talk to a remote server."
112112
},
113113

114114
"lifecycle-hooks": {

0 commit comments

Comments
 (0)