Friends good Sunday, I need to add data to an Array, I'm making a kind of shopping cart and I'm at the point where I need to add to a list the products that the end customer wants to buy, the way I use is as follows:
<div class="col-sm-4 text-right" style="width:90px">
<h-number value="inicial" min="0" max="10" step="1" change="realizarSuma(co,inicial)"></h-number>
<div class="precio">
${{co.precio*inicial}}
</div>
</div>
This goes like this: Through a number-picker I assign value="inicial"
that is $scope.inicial = 0;
and it goes adding or subtracting, in the value change="realizarSuma(co,inicial)"
that is like a kind of ng-change
that reacts to the change of the buttons + o - I send co
that corresponds to an array with all the caffe information available (in this case it sends 3 array) and finally command the value inicial
which is the number of the amount that was requested.
$scope.realizarSuma = function(item,inicial){
var producto = item.producto;
var contador = inicial;
var precio = item.precio;
var numerico = item.numerico; //identificador
var preciototal = precio*contador; //total de compra por producto
$scope.coffedate = [];
$scope.coffedate.push({total:preciototal,identificador:numerico})
console.log($scope.coffedate);
}
What I do here after passing the data to a variable is to add the data to an array to measures that are closed by pressing + or - but the problem is that the value is replaced (as seen in the image) and that It does not work for me.
I think I need to receive the data with a condition, for that I have numerico
that is a unique value of each product, so I tried to do a kind of search with for
when pressing + or - to scroll through the for and find if there is numerico
and if it exists that saves the last value.
but something is wrong, please help!