【问题标题】:How to Pass "reloadOnSearch: false" parameter with ui-sref-opts如何使用 ui-sref-opts 传递“reloadOnSearch:false”参数
【发布时间】:2017-07-21 18:31:03
【问题描述】:

我有以下状态配置:

.state('test', {
                    url: '/info',
                    templateUrl: 'views/test.html',
                    // reloadOnSearch:false
                })

我不想在状态配置中启用 reloadOnSearch = false。因为这种方式不允许用户更改 URL 并查看新数据。所以我想将此参数与 ui-sref-opts 一起传递。

我在互联网上尝试了足够多的搜索,但这似乎不起作用:

这是我的 HTML:

<tab ui-sref="test" ui-sref-active="active" active="testingState">
.......
</tab>

我试图通过 ui-sref-opts 传递“reloadOnSearch: false”,但这似乎不起作用。

谁能帮帮我。

【问题讨论】:

    标签: angularjs angular-ui-router


    【解决方案1】:

    我记得不久前必须这样做,以便在进行搜索/过滤时保存浏览器历史记录。我发现我使用的帖子帮助我解决了这个问题,虽然它有点 jankey (https://github.com/angular-ui/ui-router/issues/1079):

    //set the reloadOnSearch on state to false initially in some code block
    $state.current.reloadOnSearch = false;
    
    // update query string here
    $location.search({"from": 1, "to": 2});
    
    //revert reloadOnSearch on the state!
    $timeout(function () {
        $state.current.reloadOnSearch = undefined;
    });
    

    我相信您应该能够将此代码放置在导致页面刷新的任何内容中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-20
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多