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

Commit c28b003

Browse files
authored
docs(HTTP Client): edit copy to conform to G-doc guidelines. (#2630)
1 parent 2f5306f commit c28b003

16 files changed

+403
-396
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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
}
Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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-list.component.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
<h1>Tour of Heroes ({{mode}})</h1>
33
<h3>Heroes:</h3>
44
<ul>
5-
<li *ngFor="let hero of heroes">
6-
{{hero.name}}
7-
</li>
5+
<li *ngFor="let hero of heroes">{{hero.name}}</li>
86
</ul>
9-
New hero name:
10-
<input #newHeroName />
11-
<button (click)="addHero(newHeroName.value); newHeroName.value=''">
12-
Add Hero
13-
</button>
14-
<div class="error" *ngIf="errorMessage">{{errorMessage}}</div>
7+
8+
<label>New hero name: <input #newHeroName /></label>
9+
<button (click)="addHero(newHeroName.value); newHeroName.value=''">Add Hero</button>
10+
11+
<p class="error" *ngIf="errorMessage">{{errorMessage}}</p>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { HeroService } from './hero.service.promise';
88
selector: 'hero-list-promise',
99
moduleId: module.id,
1010
templateUrl: 'hero-list.component.html',
11-
providers: [ HeroService ]
11+
providers: [ HeroService ],
12+
styles: ['.error {color:red;}']
1213
})
1314
// #docregion component
1415
export class HeroListPromiseComponent implements OnInit {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { HeroService } from './hero.service';
88
moduleId: module.id,
99
selector: 'hero-list',
1010
templateUrl: 'hero-list.component.html',
11-
providers: [ HeroService ]
11+
providers: [ HeroService ],
12+
styles: ['.error {color:red;}']
1213
})
1314
// #docregion component
1415
export class HeroListComponent implements OnInit {

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Hero } from './hero';
99
@Injectable()
1010
export class HeroService {
1111
// URL to web api
12-
private heroesUrl = 'app/heroes.json';
12+
private heroesUrl = 'app/heroes';
1313

1414
constructor (private http: Http) {}
1515

@@ -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);
@@ -37,12 +36,17 @@ export class HeroService {
3736
return body.data || { };
3837
}
3938

40-
private handleError (error: any) {
39+
private handleError (error: Response | any) {
4140
// 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
43-
let errMsg = (error.message) ? error.message :
44-
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
45-
console.error(errMsg); // log to console instead
41+
let errMsg: string;
42+
if (error instanceof Response) {
43+
const body = error.json() || '';
44+
const err = body.error || JSON.stringify(body);
45+
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
46+
} else {
47+
errMsg = error.message ? error.message : error.toString();
48+
}
49+
console.error(errMsg);
4650
return Promise.reject(errMsg);
4751
}
4852

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

Lines changed: 12 additions & 8 deletions
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
}
@@ -50,14 +49,19 @@ export class HeroService {
5049
return body.data || { };
5150
}
5251
// #enddocregion extract-data
53-
5452
// #docregion error-handling
55-
private handleError (error: any) {
53+
54+
private handleError (error: Response | any) {
5655
// 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
58-
let errMsg = (error.message) ? error.message :
59-
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
60-
console.error(errMsg); // log to console instead
56+
let errMsg: string;
57+
if (error instanceof Response) {
58+
const body = error.json() || '';
59+
const err = body.error || JSON.stringify(body);
60+
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
61+
} else {
62+
errMsg = error.message ? error.message : error.toString();
63+
}
64+
console.error(errMsg);
6165
return Observable.throw(errMsg);
6266
}
6367
// #enddocregion error-handling, methods
Lines changed: 16 additions & 20 deletions
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
}
Lines changed: 11 additions & 0 deletions
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

Lines changed: 7 additions & 13 deletions
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/_examples/server-communication/ts/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<meta charset="UTF-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="stylesheet" href="styles.css">
9-
<link rel="stylesheet" href="sample.css">
10-
119

1210
<!-- Polyfill(s) for older browsers -->
1311
<script src="node_modules/core-js/client/shim.min.js"></script>

public/docs/_examples/server-communication/ts/sample.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
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)