Changement pour appeler l'API C# par Angular

+ récupération des datas et leur affichage
This commit is contained in:
Sébastien André
2019-10-07 15:03:09 +02:00
parent 9710b37353
commit b98adf88ca
8 changed files with 76 additions and 26 deletions

View File

@@ -1,16 +1,32 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { DropZoneResp } from '../models/dropzone';
import { JumpResp } from '../models/jump';
import { Observable } from 'rxjs/Observable';
import { tap, map } from 'rxjs/operators';
@Injectable()
export class ServiceApi {
constructor(private http: HttpClient) { }
public getListOfDropZones() {
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
const headers = new HttpHeaders({
'Access-Control-Allow-Origin': 'https://localhost:44344',
'Access-Control-Allow-Origin': 'http://localhost:5000',
});
return this.http.get<Array<DropZoneResp>>('https://localhost:44344/api/DropZone', { headers: headers });
return this.http.get<Array<DropZoneResp>>('http://localhost:5000/api/DropZone', { headers: headers })
.pipe(
map(x => x.map(data => new DropZoneResp(data))),
// tap(event => console.log(`fetched coinrankings`)),
// catchError(this.handleError('getCoinrankings', []))
);
}
public getListOfJumps(): Observable<Array<JumpResp>> {
const headers = new HttpHeaders({
'Access-Control-Allow-Origin': 'http://localhost:5000',
});
return this.http.get<Array<JumpResp>>('http://localhost:5000/api/Jump', { headers: headers });
}
}