I create buttons in ng-repeat and set value for each one.
I want to get the value from a selected button and add to array, and, if clicked other buttons, also add the value to the array as an object.
If clicked again the same button, the value should be removed object from the array.
<div ng-repeat="room in Rooms">
...
<button id="HR_{{room.Id}}" value="{{room.Id}}" onclick="AddToCart({{room.Id}})">Add To Cart</button>
</div>
Javascript:
var cartlist = [];
function AddToCart(n) {
var c = $("#cartcount").text();
cartlist.push({
Id: n,
});
$("#cartcount").text(parseInt(c) + 1);
}
this code onclick="AddToCart({{room.Id}})" cause an error. I use ng-click but I could not get an answer.
ng-click="functionOnScope(room)".onclick="AddToCart(room.Id)"should work. you don't need interpolation inside the handler.eventtoAddToCartand get thevalueof clicked button usingevent.target.value.