Bonjour,

Je travail sur un projet Angular depuis plusieurs sans aucun problème. Aujourd'hui impossible de me connecter à mon api. Voici l'erreur que j'obtiens
Access to XMLHttpRequest at 'http://localhost:8888/MoutteCAPI/backend/api/calendar/listCalendar.php' from origin 'http://localhost:4201' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Sachant que mon code marchait très bien hier et que je n'ai rien modifier entre temps.


Voici le code où je fais appel à mon api
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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}`);
  }
}