Reading json file from local (for Android / iOS)

update: ionic 2 beta (version date 10 Aug 2016) Tested!

You must add prefix to local url like this prefix + ‘your/local/resource.json’.

prefix by platform:
ios = '…/www/'
android = '…/www/'
browser = ‘’

we can create an urlResolver provider to do this job.

notice: only change url in *.ts code to access local resource, don’s do this with remote url or in html code.
Have fun and good luck with beta version.

  • An Starter Ioner
1 Like

Hi ozexpert

Try a more elegant sollution: a Service:

.service('Language', ['$resource', '$q', function ($resource, $q) {
                this.get = function () {
                    var deferred = $q.defer();
                    if (!app.text) {
                        var arquivoTraducao = 'language/language_' + app.language + '.json';
                        $resource(arquivoTraducao).get(function (data) {
                            app.text = data;
                            deferred.resolve(true);
                        });
                    }else{
                        deferred.resolve(true);
                    }

                    return deferred.promise;
                };
            }])

The file is located at folder language under www. Works for all platforms.

i try to read from a local json but it doesn’t work on my iphone,
are there any news?

  var url = "";
  if (ionic.Platform.isAndroid()) {
    url = "/android_asset/www";
  }
  $http.get(url + '/data/data.json')
    .success(function (data) {    
  });

data.json is located at “www/data/data.json”