0

This is my app state

  .state('app', {
      url: "/?:site_id",
      templateUrl: "/controls/angular/templates/partial/app.html",
      abstract: true
  })
  .state('app.popup', {
    url: "popup",
    templateUrl: "/controls/angular/templates/popup.html",
    controller: 'PopupController'
  })

The app root (that config as abstract) has parameter (site_id) that I can use in all other pages in the application.

I have drop-down list that can change the site. How can I add the site url parameter to current page with all other parameters that exist

Just change the root site_id parameter.

     var oSelect =  $('#site_select_tag').select2();
        oSelect.on("change", function (e) {
       var curr_site_id = e.val;                                
       $state.go to => ?????????                               
       //scope.site_id = e.val;
       scope.onChange()(e.val);
});
2
  • Are you looking to pass the parameters in $state.go ?? Commented Feb 18, 2016 at 10:05
  • I don't know what the options to add single parameter to current state (with parameters), I add the "state go" just for example. Commented Feb 18, 2016 at 10:11

3 Answers 3

1

Thanks

The solution is simple

$state.go('.', {site_id: e.val})

Keep all other parameters and set the new parameter

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

1 Comment

quick and easy way. It should be the answer.
0

You can pass options to the go method of $state:

$state.go(to [, toParams] [, options])

https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

$state.go('myState', {'myParam': myValue});

And you can set parameters on ui-sref:

ui-sref='stateName({param: value, param: value})'

https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref

<a ui-sref="myState({'myParam': myValue})">myLink</a>

You can access the current state as $state.current.name and the current parameters as $state.params so what you can do is this:

var params = $state.params;
params.id = 123; // Set new ID
$state.go($state.current.name, params);

2 Comments

But like I said I don't know what the state is and what the other parameters are.
Ok, edited my answer. Hope i understood you correctly this time.
0

If I understand you correctly your trying to manipulate the state data after it is set up in the $stateProvider. If so you should set up your own state provider like Mean.io do

// $meanStateProvider, provider to wire up $viewPathProvider to $stateProvider
angular.module('mean.system').provider('$meanState', ['$stateProvider', '$viewPathProvider', function($stateProvider,viewPathProvider){
    function MeanStateProvider() {
        this.state = function(stateName, data) {
          if (data.templateUrl) {
            data.templateUrl = $viewPathProvider.path(data.templateUrl);
          }        
          $stateProvider.state(stateName, data);        
          return this;
        };    

        this.$get = function() {
          return this;
        };
    }
    return new MeanStateProvider();
    }]);

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.