From 85e6e89b277f55fb44f9cb28fc6f64ba08decf04 Mon Sep 17 00:00:00 2001 From: V Sai Prakash Date: Thu, 19 Mar 2020 14:47:04 +0530 Subject: [PATCH] deep cloning the location object to lose reference. --- .../service-delivery-dashboard.directive.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/custom/icds_reports/static/js/directives/service-delivery-dashboard/service-delivery-dashboard.directive.js b/custom/icds_reports/static/js/directives/service-delivery-dashboard/service-delivery-dashboard.directive.js index 497457287068..5517ff775b6b 100644 --- a/custom/icds_reports/static/js/directives/service-delivery-dashboard/service-delivery-dashboard.directive.js +++ b/custom/icds_reports/static/js/directives/service-delivery-dashboard/service-delivery-dashboard.directive.js @@ -461,7 +461,10 @@ function ServiceDeliveryDashboardController($rootScope, $scope, $http, $location // end mobile helpers vm.getData = function () { - var requestParams = $location.search(); + // If $location.search() is directly assigned to requestParams variable, It is assigned along with reference. + // So, any change made to requestParams will be reflected in $location also (affecting the url). To avoid this, + // we are deep cloning the object ($location.search()) before assigning it to request params + var requestParams = JSON.parse(JSON.stringify($location.search())); if (isMobile) { var mobileCustomParams = vm.getMobileCustomParams(); for(var k in mobileCustomParams) { @@ -481,7 +484,6 @@ function ServiceDeliveryDashboardController($rootScope, $scope, $http, $location vm.setDtColumns(); if (isMobile) { vm.generateSortableKpiData(); - vm.resetUrl(mobileCustomParams); } }, function (error) { @@ -490,15 +492,6 @@ function ServiceDeliveryDashboardController($rootScope, $scope, $http, $location ); }; - vm.resetUrl = function (mobileCustomParams) { - // resets all the params added in url to make network request for mobile - for(var k in mobileCustomParams) { - if (mobileCustomParams.hasOwnProperty(k)) { - $location.search(k, null); - } - } - }; - $scope.$on('filtersChange', function () { vm.getData(); });