javascript - How to keep the params the same across multiple state with AngularJS router? -


i have search page many different filters. clicking on filter append url. doing this:

var params = { color: blue, shape: circle}; $location.search(params); 

there no filters, 1 filters, or dozen. depends on user clicks. when change states, url loses params. none of states other root has url assigned it. , it's hard hardcode in url because totally depends on filters user clicks on.

is there way url/params stay same when switching states?

normally, $location.search(params) keep parameters intact across page changes...

how redirect different routes?

if use

<a href='somelocation'>  

then params overwritten. if use $location.path(...)

$scope.gotosomelocation = function(){     $location.path('/somelocation');  }  <a ng-click='gotosomelocation()'>  

then params should remain intact.

as pointed out in comments, save parameters in service well:

    var myapp = angular.module('myapp', []);      myapp.service('myservice', function () {         var parameters= 'test';         return {              getparameters: function(){ return parameters},             setparameters: function(input){ parameters= input;}         };     });      myapp.controller('firstctrl', function($scope, myservice) {         $scope.parameters= myservice.getparameters();     });      myapp.controller('secondctrl', function($scope, myservice) {         $scope.parameters= myservice.getparameters;     }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -