State not changing in cordova, but yes in browser

I am having issues with state changing in iOS emulator. The issue comes when the state has something to resolve, I mean:

.state('visitors', {
  url: '/visitors',
  templateUrl: 'views/visitors.html',
  controller: 'VisitorsController',
  resolve: {
    visitors: function(VisitorsFactory) {
      return VisitorsFactory.get();
    }
  }
});

When I do the tests in my local environment with Chrome it works rightly, the issue is only when I try it in the emulator. Nothing is being logged in the console.

Thanks!

Hmm hard to tell just by looking at it, any way you could set up a simple codepen or plunkr for us to test out?

Sorry for the late answer, but I have been abroad this weekend. Here is the plunkr: http://plnkr.co/edit/3lZi11C2QHQjlcRyeYmG?p=preview

Anyway, I think that is “unuseful” because is working rightly in iOS Mobile Safari. Furthermore, I tried to serve my project, with grunt serve, and view it from my iPhone and it’s working also rightly. So, I am starting to think that could be something related to cordova, because if I do a cordova serve, it’s not working either from my iPhone OR desktop Chrome.

I don’t know how to debug it or what else to do. I have one console.log inside the resolve block and another in the controller and both are NOT showed, pretty weird… I hope you guys could give me a hand.

Thanks you!!!

Hmm not sure what to tell you, just downloaded the plunkr files and served them from Cordova and they worked fine for me.

What version of Cordova are you using?

3.4.0-rc.2

I will try tomorrow to upload a more real project, like mine and be sure that is failing with Cordova. Then, I will post here and let’s see if we can see anything. Thanks you!

Hmm just realized I was also serving an android project, I’ll check using an iOS build tomorrow and see if it makes any difference.

I just forked the ionic-angular-cordova-seed in https://github.com/JavierMartinz/ionic-angular-cordova-seed and added a commit with the issue. You can clone it and check it out

Steps to reproduce it:

  1. git clone git@github.com:JavierMartinz/ionic-angular-cordova-seed.git
  2. cordova platform add ios
  3. cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
  4. cordova emulate ios

I just discovered the bug! It’s an ngMin issue:

I only had to annotate the dependency injection for each resolve, since ngMin doesn’t support ui-router yet. So, for the post example the fixed solution would be:

.state('visitors', {
  url: '/visitors',
  templateUrl: 'views/visitors.html',
  controller: 'VisitorsController',
  resolve: {
    visitors: ['VisitorsFactory', function(VisitorsFactory) {
      return VisitorsFactory.get();
    }]
  }
});

Thanks anyway!!

3 Likes

Nice catch. I don’t like using ngMin myself. However, I also never thought to use the string injection technique inside my resolves; so I was going to git bit on minificatation. Thanks for showing the way.

Holy shit! This was driving me mad, thank god I found your solution.

How did you debug this to find the solution?

Because I had a similar problem with other stuff, so I tried the same solution :slight_smile: