@ -5,6 +5,7 @@
|
||||
import { ExceptionService, SpinnerService, ToastService } from '../../core';
|
||||
import { Http } from '@angular/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Hero } from './hero.model';
|
||||
// #enddocregion example
|
||||
|
||||
@ -19,13 +20,13 @@ export class HeroService {
|
||||
) { }
|
||||
|
||||
getHero(id: number) {
|
||||
return this.http.get(`api/heroes/${id}`)
|
||||
.map(response => response.json().data as Hero);
|
||||
return this.http.get(`api/heroes/${id}`).pipe(
|
||||
map(response => response.json().data as Hero));
|
||||
}
|
||||
|
||||
getHeroes() {
|
||||
return this.http.get(`api/heroes`)
|
||||
.map(response => response.json().data as Hero[]);
|
||||
return this.http.get(`api/heroes`).pipe(
|
||||
map(response => response.json().data as Hero[]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// #docregion example
|
||||
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';
|
||||
@ -19,13 +20,13 @@ export class HeroService {
|
||||
) { }
|
||||
|
||||
getHero(id: number) {
|
||||
return this.http.get(`api/heroes/${id}`)
|
||||
.map(response => response.json() as Hero);
|
||||
return this.http.get(`api/heroes/${id}`).pipe(
|
||||
map(response => response.json() as Hero));
|
||||
}
|
||||
|
||||
getHeroes() {
|
||||
return this.http.get(`api/heroes`)
|
||||
.map(response => response.json() as Hero[]);
|
||||
return this.http.get(`api/heroes`).pipe(
|
||||
map(response => response.json() as Hero[]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// #docregion
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { LoggerService } from '../logger.service';
|
||||
import { SpinnerState, SpinnerService } from './spinner.service';
|
||||
|
@ -1,6 +1,6 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
export interface SpinnerState {
|
||||
show: boolean;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Hero, HeroService } from './shared';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Hero, HeroService } from './shared';
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http } from '@angular/http';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@ -12,7 +12,8 @@ export class HeroService {
|
||||
constructor(private http: Http) {}
|
||||
|
||||
getHeroes(): Observable<Hero[]> {
|
||||
return this.http.get('api/heroes')
|
||||
.map(resp => resp.json().data as Hero[]);
|
||||
return this.http.get('api/heroes').pipe(
|
||||
map(resp => resp.json().data as Hero[])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,8 @@
|
||||
import { OnInit } from '@angular/core';
|
||||
import { Http, Response } from '@angular/http';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/finally';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError, finalize, map } from 'rxjs/operators';
|
||||
|
||||
import { Hero } from '../shared/hero.model';
|
||||
|
||||
@ -18,11 +16,11 @@ export class HeroListComponent implements OnInit {
|
||||
constructor(private http: Http) {}
|
||||
getHeroes() {
|
||||
this.heroes = [];
|
||||
this.http.get(heroesUrl)
|
||||
.map((response: Response) => <Hero[]>response.json().data)
|
||||
.catch(this.catchBadResponse)
|
||||
.finally(() => this.hideSpinner())
|
||||
.subscribe((heroes: Hero[]) => this.heroes = heroes);
|
||||
this.http.get(heroesUrl).pipe(
|
||||
map((response: Response) => <Hero[]>response.json().data),
|
||||
catchError(this.catchBadResponse),
|
||||
finalize(() => this.hideSpinner())
|
||||
).subscribe((heroes: Hero[]) => this.heroes = heroes);
|
||||
}
|
||||
ngOnInit() {
|
||||
this.getHeroes();
|
||||
|
@ -1,8 +1,7 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@ -10,6 +9,6 @@ import { Hero } from './hero.model';
|
||||
export class HeroService {
|
||||
getHeroes() {
|
||||
let heroes: Hero[] = [];
|
||||
return Observable.of(heroes);
|
||||
return of(heroes);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http, Response } from '@angular/http';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@ -10,8 +11,8 @@ export class HeroService {
|
||||
constructor(private http: Http) { }
|
||||
|
||||
getHeroes() {
|
||||
return this.http.get('api/heroes')
|
||||
.map((response: Response) => <Hero[]>response.json());
|
||||
return this.http.get('api/heroes').pipe(
|
||||
map((response: Response) => <Hero[]>response.json()));
|
||||
}
|
||||
}
|
||||
// #enddocregion example
|
||||
|
@ -1,8 +1,7 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@ -10,6 +9,6 @@ import { Hero } from './hero.model';
|
||||
export class HeroService {
|
||||
getHeroes() {
|
||||
let heroes: Hero[] = [];
|
||||
return Observable.of(heroes);
|
||||
return of(heroes);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@ -10,6 +9,6 @@ import { Hero } from './hero.model';
|
||||
export class HeroService {
|
||||
getHeroes() {
|
||||
let heroes: Hero[] = [];
|
||||
return Observable.of(heroes);
|
||||
return of(heroes);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
import { AppModule } from './app/app.module';
|
||||
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
|
Reference in New Issue
Block a user