如何使用route而不是ui-sref以编程方式传递param

时间:2016-03-23 11:19:14

标签: angularjs routes angular-ui-router params

我在$ stateProvider中有这样的状态

$stateProvider.state('rubricacontatti.home', {
  url: '/home/:section',
  templateUrl: 'rubricacontatti/static/html/rubricacontatti.home.html',
});

我必须以编程方式传递param部分而不使用ui-sref或$ state.go。由于项目选择,我限制使用它:

      route: 'rubricacontatti.home'

如何将param传递给路线?

1 个答案:

答案 0 :(得分:0)

我不确定您是如何以编程方式获取值,但stateConfig具有params属性,该属性接受具有任意数量属性的对象。应该可以设置它们。

$stateProvider.state('rubricacontatti.home', {
    url: '/home/:section',
    templateUrl: 'rubricacontatti/static/html/rubricacontatti.home.html',
    params: {
       myParam1: "programmatically set value"
    }
});

请参阅$stateProvider docs