2
I have a function ng-click
:
ng-click = "adicionar(0);"
This function ng-click
is inside the loop ng-repeat = "mercadoria in listademercadoria"
.
There is a way to pass on information according to the repeat in which it is contained?
Way I’m trying, unsuccessfully:
ng-click = "adicionar({{mercadoria.mercadoria}});"
Follows code Angularjs:
angular.module('meumodulo', [])
.controller('mercadoriaCarrinho', function($rootScope, $http) {
var ctrl = this;
$rootScope.listademercadoria = [];
$rootScope.mercadoria0 = {
id: 'id1',
setor: 'setor1',
foto: 'foto1',
descr: 'descr1',
de: de1,
por:por1,
mercadoria: '0',
quantidade: 1
}
$rootScope.listademercadoria.push($rootScope.mercadoria1);
$rootScope.mercadoria1 = {
id: 'id2',
setor: 'setor2',
foto: 'foto2',
descr: 'descricao2',
de: de2,
por: por2,
mercadoria: '1',
quantidade: 1
}
$rootScope.adicionar = function (a){
{
$rootScope.listademercadoria[a].quantidade=$rootScope.listademercadoria[a].quantidade + 1;
}
}
});
HTML button that would perform the action of adding one to the quantity, in the merchandise with index in which it is contained:
<button ng-click = "adicionar({{mercadoria.mercadoria}});"> + </button>
I emphasize that functions of another type, of other buttons parallel to this, are working correctly, but only in this function I am not able to make it work properly.
Your index has to be static? if you can’t pass it with add($index)
– Felipe Duarte