0

Assume that we define state like this:

(function() {
    'use strict';

    angular.module('app').config(stateConfig);

    function stateConfig($stateProvider) {
        $stateProvider
        .state('baseInformation', {
            parent: 'panel',
            params: {
                param1: null
            },
            data: {
                data1: 'sample data'
            },
            url: 'baseInformation',
            views: {
                'panel': {
                    templateUrl: 'app/baseInformation.html',
                    controller: 'BaseInformationController',
                    controllerAs: 'vm'
                }
            }
        });
    }

})();

I want to change the value of data when using $state.go, please note i don't want to use from params. maybe something like this:

$state.go('baseInformation', {data1: 'data1 changed'});

Is there a way to do this, with $state.go or other thing?

4
  • 1
    I don't think it's possible to modify the data - this seems to be specifically what params were created for. Why don't you want to use them? Commented May 23, 2018 at 17:33
  • Dear Lex my main problem is that i want to change state parameter values from specific service or either controller and cannot do that. for example with something like this: $transition$.params().param1 = -1; Commented May 23, 2018 at 17:33
  • 1
    I don't know what your use case is here and this is not really the proper forum to get into that discussion, but we use data to set static information for a state (title, whether certain elements should be shown, etc.) because it's a nice place to consolidate all of that. params are meant to pass initial dynamic data to a state. I don't see that either of those require modification outside of the state transition so perhaps you are approaching whatever problem you're trying to solve from the wrong direction. Commented May 23, 2018 at 18:01
  • if you want to pass some dynamic custom data, then i would suggest to use $statechange to identify the state change event and pass your dynamic params. Hope this will help. $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, options){ event.preventDefault(); // transitionTo() promise will be rejected with // a 'transition prevented' error }) Commented May 28, 2018 at 11:24

1 Answer 1

0

You can provide change you want as paramater in your template if needed. Read this tutorial, it may be helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.