Update $ stateParams in ui-router after calling $ location.search ()

I have an angular app that uses an ionic structure that uses a ui-router on the back.

In one of my controllers, I call:

$location.search('filter','sometext'); 

I have reloadOnSearch disabled in my routing configuration. I noticed that updating the location does not update $stateParams . Is there a way to get $stateParams update as the location updates? I looked at the ui-router documentation, but saw nothing about this script, but maybe I skipped it.

+5
source share
1 answer

I had a similar situation. You cannot track route updates if you disabled reloadOnSearch , but I found a solution for this case.

Watch out for $stateParams :

 $scope.$watchCollection('$stateParams', function (newParams) { var search = $location.search(); if (angular.isObject(newParams)) { angular.extend(search, newParams); } $location.search(search).replace(); }); 

Change $stateParams , not the route:

 $scope.$stateParams.offset += $scope.$stateParams.limit; 

A fully working example .

+5
source

Source: https://habr.com/ru/post/1206965/


All Articles