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?
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.