Rest services using $resource do not work on emulators

Hi, I finally reached the final steps of my app (11bc2ed5), everything works great on browser view but when I made a build the app do not show any resources hat should be retrieved by the ngResource.

A quick look to my resources.js:

angular.module(‘’, [])

.factory('Resources', ['$resource',
      return {
              Produits: $resource('',{}, {
                          'query': { method:'GET', isArray:true, responseType:'json' }
              Recettes: $resource('http:/',{}, {
                          'query': { method:'GET', isArray:true, responseType:'json' }

              Recette:  $resource('',{id: '@id'}, {
                          'get': { method:'GET', isArray:false, responseType:'json' }

My model (app.js)

angular.module('starter', ['ionic', 'starter.controllers', '','ngResource'])

The scripts from index.html:

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic/js/angular-resource.min.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>

The Ionic.project:

  "name": "CeliaLib",
  "app_id": "11bc2ed5",
  "gulpStartupTasks": [
  "watchPatterns": [

And the Package.json:

  "name": "CeliaLib",
  "version": "1.0.0",
  "description": "CeliaLibrary: An application that help people with celiac disease to in knowing whether a specific product is authorised for consuming or not. The Application has a library of special recipes for people with celiac disease.",
  "dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^1.3.3",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0"
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "shelljs": "^0.3.0"
  "cordovaPlugins": [
  "cordovaPlatforms": [

I think it might be dependeny problem with the angular-resource but I can’t figure-out.Can anyone help me please.

What do you see in console?
If you haven’t done it yet, I recommend that you debug your app on real device connected via USB and using Chrome remote debugging.
You might have a problem of CORS error when accessing your server, search the forum it’s very common.

Regarding your REST resources, your URLs are not very REST:

  • don’t put ‘get’ in the URL as it should represent a resource on which you can use GET, POST, DELETE, …
  • be consistent either you use always plural or you don’t (produits versus recette)

You could rewrite them as this (I don’t know what means v100):

Create a service per resource don’t group several ones in one service.
For instance, you could write a Recette service defined this way:

.factory('Recette', function ($resource) {
    return $resource('', {}, {
        'query': { method: 'GET', isArray: true},
        'get': {
            method: 'GET',
            transformResponse: function (data) {
                data = angular.fromJson(data);
                // do something with your data
                return data;
        'update': { method:'PUT' }

Thank you gmarziou,
I edited my resources now I have this:

angular.module('', [])

.factory('Recette', function($resource){
      return $resource('',{id: '@id'}, {
                          'query': { method:'GET', isArray:true, responseType:'json' },
                           'get': { method:'GET', isArray:false, responseType:'json' }

.factory('Produit', function($resource){
      return $resource('',{}, {
                          'query': { method:'GET', isArray:true, responseType:'json'}

Sadly, I use S3 (android 4.1) which doesn’t support the remote debugging.
Concerning the CORS, I am using a real website with subfolder that has an htaccess configuration which allows Access-Control-Allow-Origin

<FilesMatch "\.(php)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"

This configuration work’s with browser testing.

I so you have deployed a Cordova Whitelist plugin.

Have you used a correct HEADER meta tag?

Default one is this one:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Unfortunately, I found it’s not working in every case, so I modified it to look like this:

<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">

Next question, it may sound stupid, but is your smartphone even connected to the internet?

And did you used appropriate permissions in AndroindManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You don’t need to believe me but it funny how many people forget to do just that.


If you can try to root it and upgrade it, it would really help.

1 Like

Sorry, but You need to go really slowly with me hh.
I have deployed the whitelist by following this tutorial:
There is no notation about header meta tag so I just added it right now.

This is my config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.celialib382105" version="0.0.1" xmlns="" xmlns:cdv="">
        An Ionic Framework and Cordova project.
  <author email="hi@ionicframework" href="">
      Ionic Framework Team
  <content src="index.html"/>
  <access origin="*"/>
  <allow-navigation href="*" />
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>

The permissions seem to be fine, but during the build operation it outputs this notation:"some input files use or override a deprecated API"
Thank you a lot! it seems that I left a lot of tasks.

Hi gmarziou, unfortunately, it can’t be upgraded furthermore. is it possible to run the tests on emulated devices?

The build works on 4.4.4 (api19) emulators but not on previous ones like the api17

I can upload the files for you. If you want to take look at the source.

Have you installed older Android runtimes using Android SDK Manager?

1 Like

Do you mean the Android Support library/Repository ?

I will download all of the previous SDK Platforms.Thank’s again!

1 Like

No problem m8, you only need to ask if you need more help :smile:

1 Like

I download all of the SDK platforms, unfortunately, the app is still not retrieving the services.
would you mind if you take a look at my source code for testing? You will do a great favor for me.

Can you create a GitHub repository of this code?

Right away.

Many thanks

I have the same problem running from the android emulator could you solve it?