简体   繁体   English

AngularJS UI路由器reloadOnSearch无法正常工作

[英]AngularJS UI-Router reloadOnSearch not working as expected

I have a view where it is possible to have different objects loaded based on an ID. 我有一个视图,可以根据ID加载不同的对象。 It is a get request and the controller or state should not entirely reload. 这是一个获取请求,控制器或状态不应完全重载。 I am using ui-router and I've come across the "reloadOnSearch" property. 我正在使用ui-router,并且遇到了“ reloadOnSearch”属性。 Setting this to false should not reload the controller based on the params, it should only reload on state change. 将其设置为false不应基于参数重新加载控制器,而应仅在状态更改时重新加载控制器。 However this is not working. 但是,这不起作用。 Here is my config function: 这是我的配置功能:

var MAIN_CONFIGURATION = {
Setup: function(app) {
    app.config(["$stateProvider", "$urlRouterProvider", function($stateProvider, $urlRouterProvider) {
        $stateProvider.state("myState",
            {
                url: "/mystate/:id",
                reloadOnSearch: false,
                templateUrl: "/app/Main/templates/test.html?version=0.0.0.0001",
                controller: testCtrl
            });

        $urlRouterProvider.when("", ["$state", function($state) {
            $state.go("myState");
        }]);
    }]);
    .
    .
    .
    }
};

Below is my partial HTML: 以下是我的部分HTML:

<tr ng-repeat="item in items" ui-sref="myState({id: '{{item.ID}}'})">
                <td>{{item.FirstName}}</td>
                <td>{{item.LastName}}</td>
            </tr>

Basically a bunch of table rows are generated and when a row is clicked on, I am expecting the controller to not entirely reload. 基本上会生成一堆表行,并且当单击某行时,我希望控制器不会完全重新加载。 However, it does. 但是,确实如此。 Even when pressing the back and forward buttons on the browser, it is being reloaded. 即使按下浏览器上的后退和前进按钮,也会重新加载它。

I have no idea what I am doing wrong, any help would be appreciated. 我不知道我在做什么错,任何帮助将不胜感激。

Actually I just figured it out. 其实我只是想通了。 The route must contain "query" parameters. 该路由必须包含“查询”参数。 Thus I cannot use "/mystate/:id". 因此,我不能使用“ / mystate /:id”。 I should instead use "/mystate?id". 我应该改用“ / mystate?id”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM