Ui-router and iOS (stateProvider)

Hello everyone,

I’m trying to develop a mobile app with ionic and ngCordova but I have a big problem with iPhone. I use ui-router to get my params in url by example /menu/product/:id and this is a part of my controller which get the param :

.controller('orderCtrl', function($scope, $stateParams) { console.log($stateParams.id);

Everything work on desktop, with Chrome, Safari or Firefox. However, when I build my App for iOs (I didn’t try for Android) nothing work, I cannot get the param, nothing appears in the console. Do you have an idea?? Even if I put the $stateParams.id in a scope and display it with {{id}} I can see in browser but not on my iPhone

Thanks a lot

can you show us your config for this route/state?

Hello, this is the config :

 .state('order.productsList', {
			url: "/menu/:id",
			views: {
				"tab-orderMenu": {
					templateUrl: "app/templates/productsList.html",
					controller: "orderCtrl"
				}
			}
		})

Just for the sake of debuggin in your controller please write

$scope.$on('$ionicView.beforeEnter', function() {
  alert(window.location);
})

And paste here url of desired route that doesn’t give you correct :id

Okay it works when I definite in homepage by example /order/menu/46789, it’s okay but the page before (listing) i got

<li><a href="#/order/menu/{{ProductGroup.Id}}">{{ProductGroup.Name}}</a></li>

And in fact, I think the url doesn’t update when I change page so it doesn’t work. Why?

Thank you for helping me

You know that instead of href you can do

<a ui-sref="order.productsList({id: ProductGroup.Id})"></a>

Try that just to make sure that you are hitting correct route

Okay the route is correct, but the same problem… When I put,

$scope.$on('$ionicView.beforeEnter', function() {
alert(window.location);
})

On my phone, I didn’t have an update of the URL with Id

So do you get anything alerted at all?

When I click on my Listing menu I got an alert with the correct URL /menu/order but in the listing when I click on a item I don’t have any message on my phone but in browser I get /menu/order/Id correctly. I can upload the source code if you want

yes if I see whole code I can help quicker. Preferably on ionic playground or plukr

This is the whole code, can I put multiple files en ionic playground???
https://github.com/florianmari/ionic_try

Try to run this.getProducts(); inside of beforeEnter. So move

$scope.$on('$ionicView.beforeEnter', function() {
  alert(window.location);
})

To the bottom of order controller and add this.getProducts(); inside of it.

Is your phone running iOS 9?
If so upgrade angular to 1.4.6 or more, it contains a patch for iOS 9 related to location

Hello everyone,

My problem is now resolved thank you!

Have a good day !

Please say how for other users that may find your post by searchnig the forum.