0

I have an application that retrieves config information from a json file using "httpClient.get".

The problem comes in when I run the application offline, as in, I open the "index.html" file, the service fails with an error "Http failure response for ./assets/config.json: 0 Unknown Error".

Example code:

let testUrl = "./assets/test.json";
let test = await this.httpClient.get(testUrl).toPromise();

Is there a way to load/read files in Angular 7 when in offline mode?

  • Does this answer your question? [How to import JSON File into a TypeScript file?](https://stackoverflow.com/questions/46991237/how-to-import-json-file-into-a-typescript-file) – HariHaran Aug 11 '20 at 11:00
  • Have you tried cache'ing files? Maybe there would be an option to save config file locally in case application goes offline and use it in that particular case when exception gets thrown? – Edgaras Aug 11 '20 at 11:04
  • You can user service workers (PWA) and provide the baseEndpoints to cache the response. this will load the request even in offline. – Mohammed Ismail Aug 11 '20 at 11:08

0 Answers0