I'm using ui router and I have 2 states.
A parent state:
.state('list', {
url: '/list',
templateUrl: 'list.html',
controller: 'ListCtrl',
resolve: {
getItem : function($http, $stateParams){
return $http.get('api/rs/getItem.json', {params: {id: $stateParams.itemId}})
.then (function (data) {
return data;
});
}
}
})
and a child state:
.state('list.item', {
url: '/:itemId',
})
well, if I call the function:
$state.go('list.item', {itemId: myItemId});
the resolve function of the parent state is called (because of inheritance). The problem is, the parent state "list"'s missing "itemId" param in the url, so the param is never caught. Likewise, if I move the resolve function to the child state "list.item", I get some errors caught by controller, who tries to inject "getItem", but fails. Could anyone tell me what's the correct way to do it? I read the docs, but I couldn't figure it out. Thank you