调用 $location.search() 后更新 ui-router 中的 $stateParams [英] update $stateParams in ui-router after $location.search() is called

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

问题描述

我有一个使用 ionic-framework 的 angular 应用程序,它在后端使用 ui-router.

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-router 文档,但没有看到有关此场景的任何信息,但也许我错过了.

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 a similar situation. You cannot track route updates if you had disabled reloadOnSearch, but I found a solution for this case.

观看$stateParams:

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

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

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

更改$stateParams,而不是路由:

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

完全工作示例.

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

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