I have an array which is:
$scope.products=[
{name:'Orange', price:'1.15'},
{name:'Apple', price:'1.08'},
{name:'Pear', price:'1.85'},
{name:'Mango', price:'2.10'},
{name:'Blueberry', price:'0.55'},
{name:'Strawberry', price:'1.40'}
];
And I've added a button to every array, since I am creating a shopping cart. I created an empty array which is the cart of the selected products, but when I try to add these objects to my new array it doesnt work. The code is the following:
<li ng-repeat="x in products | orderBy:'name'">
{{x.name + " : " + '$' + x.price}}
<button type="button" class="btn btn-dark" ng-click="addItem(x)">
Add product
</button>
</li>
and the controller is:
$scope.cart=[];
$scope.addItem = function(x){
$scope.cart.push($scope.x);
console.log($scope.cart);
};