add Subscribe in HeroesComponent
This commit is contained in:
parent
81837bdc60
commit
7f6909208e
|
@ -1,15 +1,19 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
|
import { Observable, of } from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
|
|
||||||
getHeroes(): Hero[] {
|
getHeroes(): Observable<Hero[]> {
|
||||||
return HEROES;
|
const heroes = of(HEROES);
|
||||||
|
return heroes;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ export class HeroesComponent { //определяем класс со списк
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeroes(): void {
|
getHeroes(): void {
|
||||||
this.heroes = this.heroService.getHeroes();
|
this.heroService.getHeroes()
|
||||||
|
.subscribe(heroes => this.heroes = heroes);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
Loading…
Reference in New Issue