Ram_T
Ram_T

Reputation: 8484

How to use params without showing in url?

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?

Upvotes: 1

Views: 44

Answers (1)

Ram_T
Ram_T

Reputation: 8484

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

Upvotes: 1

Related Questions