docs: refactor style guide example 03-06 (#24996)

docs: refactor style guide example 03-06


docs: refactor style guide example 03-06


docs: refactor style guide example 03-06


PR Close #24996
This commit is contained in:
Daniel 2018-07-25 13:44:47 +02:00 committed by Victor Berchet
parent d4ac9698ba
commit cf81823b07
2 changed files with 10 additions and 17 deletions

View File

@ -3,9 +3,8 @@
/* avoid */ /* avoid */
import { ExceptionService, SpinnerService, ToastService } from '../../core'; import { ExceptionService, SpinnerService, ToastService } from '../../core';
import { Http } from '@angular/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { Hero } from './hero.model'; import { Hero } from './hero.model';
// #enddocregion example // #enddocregion example
@ -16,18 +15,15 @@ export class HeroService {
private exceptionService: ExceptionService, private exceptionService: ExceptionService,
private spinnerService: SpinnerService, private spinnerService: SpinnerService,
private toastService: ToastService, private toastService: ToastService,
private http: Http private http: HttpClient
) { } ) { }
getHero(id: number) { getHero(id: number) {
return this.http.get(`api/heroes/${id}`).pipe( return this.http.get<Hero>(`api/heroes/${id}`);
map(response => response.json().data as Hero));
} }
getHeroes() { getHeroes() {
return this.http.get(`api/heroes`).pipe( return this.http.get<Hero[]>(`api/heroes`);
map(response => response.json().data as Hero[]));
} }
} }

View File

@ -1,11 +1,11 @@
// #docregion // #docregion
// #docregion example // #docregion example
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { map } from 'rxjs/operators';
import { Hero } from './hero.model';
import { ExceptionService, SpinnerService, ToastService } from '../../core'; import { ExceptionService, SpinnerService, ToastService } from '../../core';
import { Hero } from './hero.model';
// #enddocregion example // #enddocregion example
@Injectable() @Injectable()
@ -16,18 +16,15 @@ export class HeroService {
private exceptionService: ExceptionService, private exceptionService: ExceptionService,
private spinnerService: SpinnerService, private spinnerService: SpinnerService,
private toastService: ToastService, private toastService: ToastService,
private http: Http private http: HttpClient
) { } ) { }
getHero(id: number) { getHero(id: number) {
return this.http.get(`api/heroes/${id}`).pipe( return this.http.get<Hero>(`api/heroes/${id}`);
map(response => response.json() as Hero));
} }
getHeroes() { getHeroes() {
return this.http.get(`api/heroes`).pipe( return this.http.get<Hero[]>(`api/heroes`);
map(response => response.json() as Hero[]));
} }
} }