I have a Clip Service:
export class ClipService {
allClips: Clip[] = [];
private clips = new BehaviorSubject<Clip[]>(null);
constructor(private http: HttpClient) {
this.loadClips();
}
private fetchClips(body?: string): Observable<Clip[]> {
let url = myurl/clips;
try {
return this.http.get<Clip[]>(url);
} catch (e) {
console.error('Error fetching clips: ' + e);
}
}
loadClips(): void {
this.fetchclips().subscribe(allClips => this.allClips = allClips);
this.setClips(this.allClips);
}
getClips(): Observable<Clip[]> {
return this.clips.asObservable();
}
}
and a ClipComponent.ts where I cosume the service like this:
ngOnInit(): void {
this.clipService.getClips().subscribe(clips => {
this.allClips = clips;
this.clips = this.allClips;
console.log(this.clips);
this.populateFilters(this.clips);
});
}
Even though a call to the API is triggered and there are around 200 clips returned, the console.log in the component always logs an empty array.
What am I missing here?