How do I get parameters for a state from a service? I have this state:

.state('cashbox.list', {
        title: 'Cashbox',
        url: '/:from/:to?q',
        templateUrl: '/cashbox_list.html',
        controllerUrl: 'controllers/CashboxCtrl.js',
        controller: 'CashboxCtrl',
        controllerAs: 'mainCtrl',
        params: {
            from: getCashboxParamFrom,
            to: getCashboxParamTo
        },
        resolve: {
            cashboxData: getTransactionsData
        }
    })



    function getTransactionsData($stateParams)
    {
        return CashboxService.getTransactions($stateParams.from, $stateParams.to);
    }

Now my problem is, that params from and to are dynamic and are fetched by another service. I need something like a resolve before the resolve to get the params. I already tried to operate with promises in getCashboxParamTo/From but the app then stops routing when going to state. Also tried to use a parent state with redirectTo into child state but don't find anything on how to dynamically create stateparams from resolved data in parent state.

        .state('cashbox', {
            title: trns('title.cashbox_list'),
            url: '/cashbox',
            redirectTo: {
                state: 'cashbox.list',
                params: HERE DATES FROM RESOLVE
            },
            resolve: {
                dates: getFromToDates
            }
        })

Solutions with state.go won't work as I'm running into a 'The transition has been superseded by a different transition' issue.

share|improve this question
  • How about you create two revolvers, and make one dependent on the another one. So, second one will wait until first one is finished, thats the way to get params before calling service in second resolver. – mbeso Mar 20 '17 at 14:55
  • I need this redirection as resulting URL is needed for deeplinking. Nested resolves will bring up correct data for the state, but browsers address should show up underlying parameters. – HarpoMarx69 Mar 21 '17 at 10:14

The answer is to declare two states cashbox and cashbox.list. Then redirect in a onStart transition hook after fetching data from service:

$transitions.onStart({to: 'cashbox'}, function (trans)
    {
        var curMonth = gfService.getCurrentMonth();
        return $state.target('cashbox.list', {from: curMonth.dateFrom.string, to: curMonth.dateTo.string})
    });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.