2016-11-28 39 views
0

controllerA甲如何使用参数而不显示在URL中?从状态

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

状态app.js定义从状态B

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

controllerB

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

如何吨使用acName他控制器没有显示在状态的url部分?

+0

尝试givinng默认值状态PARAMS。 'params:{accountType:null,acName:null}' –

+0

如果我提到'null'我放弃它的价值。 –

回答

0

我想出了一个解决方案

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

     }) 

欲了解更多信息的params对象的squash属性:

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

相关问题