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