更新$ stateParams在$ location.search后UI的路由器()被调用 [英] update $stateParams in ui-router after $location.search() is called

查看:291
本文介绍了更新$ stateParams在$ location.search后UI的路由器()被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其使用的离子的框架,其中在后端使用UI路由器的角应用

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

我有reloadOnSearch在我的路由配置禁用。我注意到,更新位置不更新 $ stateParams 。有没有办法迫使 $ stateParams 来更新这些位置被更新?我通过UI路由器的文件看,但没有看到有关此方案的任何东西,但也许我错过了。

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.

推荐答案

我也有类似情况。你不能跟踪路由更新,如果你禁用了 reloadOnSearch ,但我发现这种情况的解决方案。

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

手表$ stateParams:

Watch $stateParams:

$scope.$watchCollection('$stateParams', function (newParams) {
    var search = $location.search();

    if (angular.isObject(newParams)) {
      angular.extend(search, newParams);
    }

    $location.search(search).replace();
});

更改$ stateParams,没有路线:

Change $stateParams, not route:

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

工作示例。

这篇关于更新$ stateParams在$ location.search后UI的路由器()被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆