I have a vector of objects with prices, product name ..., after the customer has clicked on a product I move it to another list, from ordering, after being done this needs to cause me to add the prices of list products and return me a total each time a new product is added and case removed needs to be subtracted from the total. I'm using $ scope in this application because it's an ionic app.
I'm using a service to fill this list because I have two more vectors that have the msm specifications but split the products into two more vectors to organize better and it was the solution I found. But I'm not understanding what it represents very well in the code.
.controller('pedidoCtrl', function($scope, produtoService) {
$scope.items = [];
$scope.items = produtoService.getProdutos();
$scope.deleteItem = function(item){
$scope.items.splice($scope.items.indexOf(item), 1);
};
})
.service('produtoService', [function(){
var produtosLista = [];
var addProduto = function(produto) {
produtosLista.push(produto);
};
var getProdutos = function(){
return produtosLista;
};
return {
addProduto: addProduto,
getProdutos: getProdutos,
};
}]);