update $stateParams in ui-router after $location.search() is called

£可爱£侵袭症+ 提交于 2019-12-23 12:09:11

问题


I have an angular application which is using the ionic-framework, which uses ui-router on the back end.

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 the $stateParams. Is there a way to force the $stateParams to update as the location is updated? I looked through the ui-router documentation, but didn't see anything about this scenario, but perhaps I missed it.


回答1:


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

Watch $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 route:

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

Completely working example.



来源:https://stackoverflow.com/questions/26953627/update-stateparams-in-ui-router-after-location-search-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!