如何在ui-router persisting stateParams上改变状态?

时间:2016-06-24 14:21:33

标签: javascript angularjs angular-ui-router ui-sref

我在angularjs中使用ui-router,我有以下代码:

blog.module.js

中的

$stateProvider
    .state('blog', {
        url: '/domains/:domain_id/blog',
        template: '<ui-view></ui-view>',
        title: 'Blog',
    })
    .state('blog.posts', {
        url: '/posts',
        template: 'Hello world',
        title: 'Posts',
    });

modules.module.js

$stateProvider
    .state('modules', {
        url: '/domains/:domain_id/modules',
        templateUrl: '/assets/templates/modules/index.tpl.html',
        controller: 'ModulesCtrl as index',
        title: 'Módulos',
    });

所有路线的:domain_id都会在我的应用中引用相同的内容。但是,如果可能的话,我需要/想要使:domain_id在所有状态更改中保持不变,而不需要在我使用的每个ui-sref上传递它。 我不知道怎么做,有人都知道吗?

非常感谢您的关注

1 个答案:

答案 0 :(得分:1)

我猜你需要在改变状态时设置状态参数。因为stateParams在状态范围内。当状态改变时,定义了新状态的范围。 $state.go('blog.posts',{'domain_id':$stateParams.domain_id});

相关问题