0

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

1 Answer 1

0

You defined itemId in the url and passing listId from the $state.go so you can replace

 $state.go('list.item', {listId: myListId});

with

$state.go('list.item', {itemId: myListId});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.