javascript - How merge two objects array in angularjs? -
i want append following object array existing 1 in angulajs implementing load more feature.
ie,appending ajax response existing 1 each time.
i have 1 variable, $scope.actions
contains following json
data,
{ "total": 13, "per_page": 2, "current_page": 1, "last_page": 7, "next_page_url": "http://invoice.local/activities/?page=2", "prev_page_url": null, "from": 1, "to": 2, "data": [ { "id": 2108, "action_type_id": 202, "user_id": 1 }, { "id": 2108, "action_type_id": 202, "user_id": 1 } ] }
i want append following json
response each time variable.
{ "data": [ { "id": 2108, "action_type_id": 202, "user_id": 1 }, { "id": 2108, "action_type_id": 202, "user_id": 1 } ] }
i have tried $scope.actions.data.concat(data.data);
but not working , getting following error message
$scope.actions.data.concat not function
you can use angular.extend(dest, src1, src2,...);
in case :
angular.extend($scope.actions.data, data);
see documentation here :
https://docs.angularjs.org/api/ng/function/angular.extend
otherwise, if new values server, can following
for (var i=0; i<data.length; i++){ $scope.actions.data.push(data[i]); }
Comments
Post a Comment