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