Skip to content

Commit

Permalink
deep cloning the location object to lose reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
saiprakash-v committed Mar 19, 2020
1 parent a5425ca commit 85e6e89
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -481,7 +484,6 @@ function ServiceDeliveryDashboardController($rootScope, $scope, $http, $location
vm.setDtColumns();
if (isMobile) {
vm.generateSortableKpiData();
vm.resetUrl(mobileCustomParams);
}
},
function (error) {
Expand All @@ -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();
});
Expand Down

0 comments on commit 85e6e89

Please sign in to comment.