File tree 2 files changed +10
-17
lines changed
aio/content/examples/styleguide/src/03-06/app/heroes/shared
2 files changed +10
-17
lines changed Original file line number Diff line number Diff line change 3
3
/* avoid */
4
4
5
5
import { ExceptionService , SpinnerService , ToastService } from '../../core' ;
6
- import { Http } from '@angular/http' ;
6
+ import { HttpClient } from '@angular/common /http' ;
7
7
import { Injectable } from '@angular/core' ;
8
- import { map } from 'rxjs/operators' ;
9
8
import { Hero } from './hero.model' ;
10
9
// #enddocregion example
11
10
@@ -16,18 +15,15 @@ export class HeroService {
16
15
private exceptionService : ExceptionService ,
17
16
private spinnerService : SpinnerService ,
18
17
private toastService : ToastService ,
19
- private http : Http
18
+ private http : HttpClient
20
19
) { }
21
20
22
21
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 } ` ) ;
25
23
}
26
24
27
25
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` ) ;
30
27
}
31
28
32
29
}
33
-
Original file line number Diff line number Diff line change 1
1
// #docregion
2
2
// #docregion example
3
+ import { HttpClient } from '@angular/common/http' ;
3
4
import { Injectable } from '@angular/core' ;
4
- import { Http } from '@angular/http' ;
5
- import { map } from 'rxjs/operators' ;
6
5
7
- import { Hero } from './hero.model' ;
8
6
import { ExceptionService , SpinnerService , ToastService } from '../../core' ;
7
+ import { Hero } from './hero.model' ;
8
+
9
9
// #enddocregion example
10
10
11
11
@Injectable ( )
@@ -16,18 +16,15 @@ export class HeroService {
16
16
private exceptionService : ExceptionService ,
17
17
private spinnerService : SpinnerService ,
18
18
private toastService : ToastService ,
19
- private http : Http
19
+ private http : HttpClient
20
20
) { }
21
21
22
22
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 } ` ) ;
25
24
}
26
25
27
26
getHeroes ( ) {
28
- return this . http . get ( `api/heroes` ) . pipe (
29
- map ( response => response . json ( ) as Hero [ ] ) ) ;
27
+ return this . http . get < Hero [ ] > ( `api/heroes` ) ;
30
28
}
31
29
32
30
}
33
-
You can’t perform that action at this time.
0 commit comments