停止搜索解析控制器数据

Stop resolving controller data on search

本文关键字:控制器 数据 搜索      更新时间:2023-09-26

如果使用$location.search(),是否有办法停止解析控制器数据

下面是我的代码
App.config(function($routeProvider, $locationProvider) {
    $routerProvider.when('/overview' {
        title:"Overview",
        controller:"OverViewCtrl",
        templateUrl:"pages/overview.html",
        resolve:{
            mainData:function(Service){
            return Service.getOverviewData();
        }
    });
});

在我的控制器中,我使用相同的

App.controller("OverViewCtrl", function($scope, $location, mainData, Service){
    $scope.data = mainData.data;
    $scope.otherData = null;
    Service.getOtherData($location.search(), function(data){
        $scope.otherData = data;
    });
    $scope.search = function(param){
        $location.search(param);
    };
});

每次调用search方法时,mainData数据从服务中加载,是否有办法在搜索时调用getOtherData服务

$routeProvider配置具有reloadOnSearch属性。从文档

[reloadOnSearch=true] - {boolean=} -重载路由时只有$location.search()或$location.hash()更改

设置为false

在控制器中订阅$route事件$routeUpdate

范围。在美元($ routeUpdate,函数(事件,args) {//您可以在这里获得其他数据。});

检查第二个参数,看看在args对象哈希中传递了什么。我相信它包含了当前路由和其他一些数据