My angle code has ng-repeat as follows:
AngularJS:
angular.module('meumodulo', [])
.controller('mercadoria', 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,
total: ''
}
$rootScope.listademercadoria.push($rootScope.mercadoria0);
$rootScope.mercadoria1 = {
id: 'id2',
setor: 'setor2',
foto: 'foto2',
descr: 'descr2',
de: 'de2',
por: 'por2',
mercadoria: '1',
quantidade: 1,
total: ''
}
$rootScope.listademercadoria.push($rootScope.mercadoria1);
$rootScope.showPanel = true;
$rootScope.listademercadoria.push($rootScope.mercadoria1);
$rootScope.remover = function(b) {
{
$rootScope.showPanel = !$rootScope.showPanel;
}
}
});
In my HTML Code, outside of the ng-repeat loop, there is the following clickable item:
<span style="margin-right: 8px;"> ou </span><a href="#" ng-click = " remover();">remover</a>
By clicking on it, the $rootScope.remover = function ()
function is fired, so it changes the boolean showPanel value, causing the next add button (contained in loop ng-repeat) becomes visible:
<button class="add" ng-show = "showPanel" id = "{{mercadoria.id}}">adicionar</button>
Explained how the system behaves, comes the question:
I've been looking for a solution for a long time, but in all possible solutions, by clicking the "remove" div, add the "add" buttons of the two divs generated by ng-repeat . How do I make visible the "add" button of ONLY ONE of the divs generated by ng-repeat?
EDITION:
I tried to put an extra property on angularJS:
$rootScope.mercadoria0 = {
id: 'id1',
setor: 'setor1',
foto: 'foto1',
descr: 'descr1',
de: de1,
por: por1,
mercadoria: '0',
quantidade: 1,
total: '',
show: 'show0'
}
$rootScope.listademercadoria.push($rootScope.mercadoria0);
$rootScope.mercadoria1 = {
id: 'id2',
setor: 'setor2',
foto: 'foto2',
descr: 'descr2',
de: 'de2',
por: 'por2',
mercadoria: '1',
quantidade: 1,
total: ''
show: 'show1'
}
$rootScope.listademercadoria.push($rootScope.mercadoria1);
So my button would get the values of the show as a dependency for ng-hide, and when it was clicked it would disappear, since the value of {{commodity.show}} would become true:
<button class="add" ng-hide = "{{mercadoria.show}}" id = "{{mercadoria.id}}" ng-click = "incluirNoCarrinho(mercadoria); {{mercadoria.show}} = true;">
And after inserting the same commodity1 and commodity0 into a new $ rootScope.carriage , I caused that ng-repeat="merchandise in cart" button remove button each time the add button is clicked. So, I pass the {{commodity.show}} = false; attribute to the ng-click remove attribute:
<span style="margin-right: 8px;"> ou </span><a href="#" ng-click = "{{mercadoria.show}}=false;">remover</a>
However, the browser reports an error and the add button simply does not do any actions when it is clicked. Here is an error:
Syntax Error: Token '{' invalid key at column 33 of the expression [incluirNoCarrinho(mercadoria); {{mercadoria.show}} = true;] starting at [{mercadoria.show}} = true;].