Reset all $stateParams to their default

Issue

How do I reset all $stateParams to their defined default? Of course, I could reset them by hand like:

$state.go(".", {
  param1: "",
  param2: 0,
  param3: false
});

But it would be nice to auto reset to their defined default.

$stateProvider
  .state("myState", {
    url: "?param1&param2&param3",
    params: {
      param1: {
        value: "",
        type: "string",
        squash: true
      }, 
      param2: {
        value: 0,
        type: "int",
        squash: true
      }, 
      param3: {
        value: false,
        type: "bool",
        squash: true
      }
    }
  });

Doing it manually forces me to look up every parameters value, before setting a value.

And I totally do NOT want to set everything to undefined, as this may break some logics.

EDIT

Adding version info:

  • AngularJS 1.6.3
  • UI-Router: 1.0.0-beta.3

Solution

A little late but if someone as the same problem:

You can set the inherit TransitionOptions to false to force the default value of params.

$state.go(".", {param1: ""}, {inherit: false});

See doc here:
https://ui-router.github.io/ng1/docs/latest/interfaces/transition.transitionoptions.html#inherit

Answered By – Charles D

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published