1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { Booking } from '../models/bookings.model';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class BookingService {
bookingSubject = new Subject<any[]>();
PHP_API_SERVER = 'http://localhost:8888/MoutteCAPI/backend/api/calendar/listCalendar.php';
private bookings: Booking[];
constructor(private httpClient: HttpClient) { }
emitBookingSubject(): void {
this.bookingSubject.next(this.bookings);
}
readListBooking(): Observable<Booking[]>{
this.httpClient.get<Booking[]>(`${this.PHP_API_SERVER}`).subscribe(
(reponse) => {
this.bookings = reponse;
this.emitBookingSubject();
},
(error) => {
console.log('erreur de sauvegarde' + error);
}
);
return this.httpClient.get<Booking[]>(`${this.PHP_API_SERVER}`);
}
} |
Partager