now it works, it was CORS
This commit is contained in:
@ -16,8 +16,8 @@ export class DashboardComponent implements OnInit {
|
||||
this.getHeroes();
|
||||
}
|
||||
|
||||
getHeroes(): void {
|
||||
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes.slice(1, 5));
|
||||
async getHeroes(): Promise<void> {
|
||||
this.heroes = await this.heroService.getHeroes()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ export class HeroDetailComponent implements OnInit {
|
||||
this.getHero();
|
||||
}
|
||||
|
||||
getHero(): void {
|
||||
async getHero(): Promise<void> {
|
||||
const id = +this.route.snapshot.paramMap.get('id');
|
||||
this.heroService.getHero(id).subscribe(hero => this.hero = hero);
|
||||
this.hero = await this.heroService.getHero(id)
|
||||
}
|
||||
|
||||
goBack(): void {
|
||||
@ -30,6 +30,6 @@ export class HeroDetailComponent implements OnInit {
|
||||
}
|
||||
|
||||
save(): void {
|
||||
this.heroService.updateHero(this.hero).subscribe(() => this.goBack());
|
||||
// this.heroService.updateHero(this.hero).subscribe(() => this.goBack());
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,24 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { Hero } from './hero';
|
||||
import { MessageService } from './message.service';
|
||||
import { HEROES } from './mock-heroes'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HeroService {
|
||||
constructor(private messageService: MessageService, private http: HttpClient) { }
|
||||
|
||||
getHeroes(): Observable<Hero[]> {
|
||||
|
||||
getHeroes(): Promise<Hero[]> {
|
||||
this.messageService.add('HeroService: fetched heroes');
|
||||
// return of(HEROES)
|
||||
return this.http.get<Hero[]>(`http://172.16.3.185:5000/heroes`)
|
||||
return this.http.get<Hero[]>(`http://172.16.3.185:5000/heroes`).toPromise()
|
||||
}
|
||||
|
||||
getHero(id: number): Observable<any> {
|
||||
getHero(id: number): Promise<Hero> {
|
||||
this.messageService.add(`HeroService: fetch hero id=${id}`);
|
||||
// return of(HEROES.find(hero => hero.id === id))
|
||||
return this.http.get<Hero>(`http://172.16.3.185:5000/hero?id=${id}`)
|
||||
return this.http.get<Hero>(`http://172.16.3.185:5000/hero?id=${id}`).toPromise()
|
||||
}
|
||||
|
||||
updateHero(hero: Hero): Observable<any> {
|
||||
|
@ -18,8 +18,12 @@ export class HeroesComponent implements OnInit {
|
||||
|
||||
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
||||
|
||||
getHeroes(): void {
|
||||
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes);
|
||||
async getHeroes() {
|
||||
try {
|
||||
this.heroes = await this.heroService.getHeroes();
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
Reference in New Issue
Block a user