Hello. I need to change the value of a variable in angularJS but I'm encountering the following problem: "Can not set property 'quantity' of undefined".
When I click the add button, I need the quantity variable contained in commodity1 to be incremented by 1.
html button:
<button ng-show="someAdicionar" class="add" ng-click = "adicionar();">+</button>
Below is the way I have tried and in all research the suggested solution is below.
AngularJS code:
.controller('mercadoriaCarrinho', function ($rootScope, $http){
$rootScope.listademercadoria=[];
$rootScope.mercadoria1 = {
id: '55',
setor: 'alimento',
foto: 'Produtos/Produto (55).jpg',
descr: 'Macarr�o Renata',
de: 15,
por: 12,
mercadoria: '1',
quantidade: 1
}
$rootScope.listademercadoria.push($rootScope.mercadoria1);
$rootScope.adicionar = function (){
{
$rootScope.listademercadoria.mercadoria1.quantidade=$rootScope.listademercadoria.mercadoria1.quantidade+1;
}
}
});
I note that other functions, other buttons parallel to it, are working correctly, but only this function has this problem.