rneves
rneves

Reputation: 2083

How to change state on ui-router persisting stateParams?

I'm using ui-router in angularjs, and I have the following code:

in 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',
    });

and 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',
    });

The :domain_id of all routes make reference to the same thing in my app. But I need/want, if it's possible, to make this :domain_id persist on all state change without need to pass it on each ui-sref that I use. I have no idea how to make this, anyone knows this?

Really thank you for your attention

Upvotes: 1

Views: 110

Answers (1)

SanchezCool
SanchezCool

Reputation: 81

I guess you need to set state params whenever you change the state.Because stateParams are within state scope.when state is changed scope of new state is defined. $state.go('blog.posts',{'domain_id':$stateParams.domain_id});

Upvotes: 1

Related Questions