jshill103
jshill103

Reputation: 320

Add variable to an existing json object

request = myService.getCases();
request.then(
function(payload) {
$scope.cases = payload.data;

var time =  Math.floor((Date.now() - Date.parse($scope.cases[i].date_case_modified))/(60000*60*24));

$scope.cases.duration.push(time);
}
});

Inside the controller I am trying to tack on the cases.duration onto the cases object but it wont add it onto the object that is returned. Any ideas?

Upvotes: 0

Views: 855

Answers (1)

Glenn Ferrie
Glenn Ferrie

Reputation: 10410

I think you just need to introduce a forEach as shown here:

request = myService.getCases();
request.then(
    function(payload) {
         $scope.cases = payload.data;

         angular.forEach($scope.cases, function (el) {
            var time =  Math.floor((Date.now() - Date.parse(el.date_case_modified))/(60000*60*24));

            el.duration = time;
        });
    }
});

Hope this helps

Upvotes: 1

Related Questions