Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to retrieve a json data file with http.get() on stackblitz

I have an angular service that looks like:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class ApiService {
  constructor(private http: HttpClient) {}

  getDataHttp(): Observable<any> {
    return this.http.get(
      'http://localhost:4200' + '/assets/data.json'
    );
  }
}

Running angular locally, this would retrieve the json file data.json in the assets directory.

Is it possible to do the same thing on Stackblitz? What would that url look like?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Edit: Stackblitz- https://stackblitz.com/edit/angular-ivy-zptuyp

>Solution :

Yes, it is possible.

Give the path direct from assets, like this –

this.httpClient.get('assets/data.json');

See the working example here

Even you can use same way on local also.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading