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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -