I want to pass json data that I get from an API into an array and display that information in my template and I don't know how to do that.
this error apears on my console :
my ts file :
this.api.getJoursFeries(year).subscribe(
(data: feries[]) => {
this.joursFeries = data;
// console.log(data);
}, (error: HttpErrorResponse) => {
console.log(error);
}
)
my service file :
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { feries } from '../models/feries';
@Injectable({
providedIn: 'root'
})
export class ApiService {
private apiBaseUrl = 'https://calendrier.api.gouv.fr/jours-feries/metropole'
constructor(private http: HttpClient) { }
getJoursFeries(annee : number): Observable<feries[]> {
return this.http.get<feries[]>(`${this.apiBaseUrl}/${annee}.json`);
}
}

Assuming that you have already defined an interface that represents the objects given from the response, you have two ways to represent that data in the template.
The easiest way is to assign an array variable from the component to the array response from the subscription and then in the template you would use *ngFor directive to display the data
A more principled way would be to create a BehaviourSubject in your service then convert it to an Observable via .asObservable() Assign this service Observable to an Observable variable in your component.ts file and then use the ngFor with the observable with the async pipe. However this requieres some knowledge of the RxJS library and how to properly work with Observables. Let me know if you need further details for the solution