Skip to content

Commit cf81823

Browse files
danielsoglvicb
authored andcommitted
docs: refactor style guide example 03-06 (angular#24996)
docs: refactor style guide example 03-06 docs: refactor style guide example 03-06 docs: refactor style guide example 03-06 PR Close angular#24996
1 parent d4ac969 commit cf81823

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

aio/content/examples/styleguide/src/03-06/app/heroes/shared/hero.service.avoid.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
/* avoid */
44

55
import { ExceptionService, SpinnerService, ToastService } from '../../core';
6-
import { Http } from '@angular/http';
6+
import { HttpClient } from '@angular/common/http';
77
import { Injectable } from '@angular/core';
8-
import { map } from 'rxjs/operators';
98
import { Hero } from './hero.model';
109
// #enddocregion example
1110

@@ -16,18 +15,15 @@ export class HeroService {
1615
private exceptionService: ExceptionService,
1716
private spinnerService: SpinnerService,
1817
private toastService: ToastService,
19-
private http: Http
18+
private http: HttpClient
2019
) { }
2120

2221
getHero(id: number) {
23-
return this.http.get(`api/heroes/${id}`).pipe(
24-
map(response => response.json().data as Hero));
22+
return this.http.get<Hero>(`api/heroes/${id}`);
2523
}
2624

2725
getHeroes() {
28-
return this.http.get(`api/heroes`).pipe(
29-
map(response => response.json().data as Hero[]));
26+
return this.http.get<Hero[]>(`api/heroes`);
3027
}
3128

3229
}
33-
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// #docregion
22
// #docregion example
3+
import { HttpClient } from '@angular/common/http';
34
import { Injectable } from '@angular/core';
4-
import { Http } from '@angular/http';
5-
import { map } from 'rxjs/operators';
65

7-
import { Hero } from './hero.model';
86
import { ExceptionService, SpinnerService, ToastService } from '../../core';
7+
import { Hero } from './hero.model';
8+
99
// #enddocregion example
1010

1111
@Injectable()
@@ -16,18 +16,15 @@ export class HeroService {
1616
private exceptionService: ExceptionService,
1717
private spinnerService: SpinnerService,
1818
private toastService: ToastService,
19-
private http: Http
19+
private http: HttpClient
2020
) { }
2121

2222
getHero(id: number) {
23-
return this.http.get(`api/heroes/${id}`).pipe(
24-
map(response => response.json() as Hero));
23+
return this.http.get<Hero>(`api/heroes/${id}`);
2524
}
2625

2726
getHeroes() {
28-
return this.http.get(`api/heroes`).pipe(
29-
map(response => response.json() as Hero[]));
27+
return this.http.get<Hero[]>(`api/heroes`);
3028
}
3129

3230
}
33-

0 commit comments

Comments
 (0)