2014-05-07 28 views
0

如果使用$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服務。

回答

0

$routeProvider配置有reloadOnSearch屬性。從文檔

[reloadOnSearch =真] - {布爾=} - 重新加載路由時僅 $ location.search()或$的location.hash()的變化。

將其設置爲false

在你的控制器,然後訂閱$route事件$routeUpdate

$範圍在$( '$路由更新' 功能(事件參數){// 這裏你可以得到其他數據 。});

檢查第二個參數以查看args對象散列中傳遞的內容。我相信它包含了當前的路線和其他一些數據。