Search code examples
angularjsangular-ui-routerurl-parameters

Angularjs ui-router add parent url parameter to current state


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);
});

Solution

  • Thanks

    The solution is simple

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

    Keep all other parameters and set the new parameter