Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Issue with data provider

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>