1

controllerA from state A

$state.go('account.accountRegister', {accountType: $stateParams.accountType, acName: acName})

State defined in app.js

.state('account.accountRegister', {
    url: '/:accountType/register',
    params: {accountType, acName},
    views: {
        'mainView@':{
        templateUrl: 'app/views/registration.html',
        controller: 'registrationController'
    }
}
})

controllerB from state B

console.log($stateParams.acName); // is getting undefined

How to use acName in the controller without showing in the url part of the state?

2
  • try givinng default values to state params. params: {accountType: null, acName: null} Commented Nov 28, 2016 at 6:09
  • if I mention null I am loosing its value. Commented Nov 28, 2016 at 6:11

1 Answer 1

1

I came up with a solution

        .state('account.accountRegister', {
                url: '/:accountType/register',
                params: {
                    acName: {
                        value: 'defaultValue',
                        squash: false
                    }
                },
                views: {
                    'mainView@':{
                        templateUrl: 'app/views/registration.html',
                        controller: 'registrationController'
                    }
                }

        })

For more info on squash property of the params object:

https://ui-router.github.io/docs/0.3.1/#/api/ui.router.state.$stateProvider

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.