Does anybody know, what I am doing wrong? I try to get a local json - assign it to a class variable and return the response as an observable — but I am not able to make this work.
export class CategoriesService {
private categories: CategoryItem[] = null;
constructor(
private http: HttpClient
) { }
getCategories(): Observable <CategoryItem[]> {
this.http.get<CategoryItem[]>('/assets/data/categories.json').subscribe(
response => {
console.log(response);
this.categories = response;
},
error => {},
() => {
return of(this.categories);
});
}
1 post - 1 participant