How to load json from asset directory in new version of angular


the common answer below isn’t working.
Whatever works don’t work in the apk .
I keep getting below errors with different configurations (loading file to loading using http)

  • errors from CORS
  • ERROR TypeError: Cannot read property ‘subscribe’ of undefined
  • Could not read response

old answer

this.http.get(link).map(res => res.json()).subscribe((data) => {
			console.log(data, "data");
		err => {
			console.log(err, "err");

loading from file

this.file.readAsText(this.url, endpoint).then((data) => {

      let myObservable = Observable.create(observer => {;
    }).catch(err => console.log(err));
return myObservable;

and the regular loading using http

observable = this.http.get("/android_asset/www/assets/mocks/file.json", reqOpts);
observable = this.http.get("/assets/mocks/file.json", reqOpts);

nothing works on device


Not sure, but there seems an RXJS version issue under the hood


This one works for me, and should be preferred over all the others.