1
Hello. I need to change the value of a variable in Angularjs but I am finding the following problem: "Cannot set Property 'quantity' of Undefined".
By clicking the button add, need the variable amount contained in market1 is increased by 1.
Html button:
<button ng-show="someAdicionar" class="add" ng-click = "adicionar();">+</button>
Below the way I tried and in every search the suggested solution is this 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 emphasize that functions of another type, of other buttons parallel to this, are working correctly, however only this function is with this problem.
It is bad practice to store data in
$rootScope
– Sorack
Thanks for the tip. Considering that I store in $Scope, would solve this my problem?
– Gymo