javascript - How to add new key in existing array in angular js? -
i have define blank array $scope.order, on form submit data , create new array merge existing array.
.controller('guestdetailsctrl',function($scope){ $scope.order = []; $scope.itemdetails = function() { // here data after form submiti have array arrieve form submit. $scope.order=$scope.order.push({name:$scope.item.name,price:$scope.item.price}); } });
i want result this.
$scope.order = [{name:'abc',price:100},{name:'pqr',price:80},{name:'xyz',price:50}];
when itemdetails() call @ time array merge new data.
push
operates on array in-place. simply
$scope.order = []; $scope.itemdetails = function() { // here data after form submiti have array arrieve form submit. $scope.order.push({name:$scope.item.name,price:$scope.item.price}); }
(without assigning it), , should work!
Comments
Post a Comment