2
My angular code has an 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 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 function $rootScope.remover = function ()
is triggered, and so it changes the value boolean of showPanel, thus making the following add button (contained in the ng-repeat loop) visible:
<button class="add" ng-show = "showPanel" id = "{{mercadoria.id}}">adicionar</button>
Explained how the system is behaving, comes the question:
I have been looking for a solution to the case for a long time, but in all possible solutions, by clicking on the div "remove", the "add" buttons of the two Ivs 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 the 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);
Thus my button would receive the values of the show as dependency for ng-Hide, and when clicked it would disappear, because the value of {{merchandise.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 market1 and mercadoria0 in a new $rootScope.cart, made that ng-repeat="merchandise in cart" call the button remove every time the button add is clicked. So, I pass the attribute {{merchandise.show}}=false; to the ng-click of remove:
<span style="margin-right: 8px;"> ou </span><a href="#" ng-click = "{{mercadoria.show}}=false;">remover</a>
But the browser is error and the add button simply does not do actions while being clicked. Follow error:
Syntax Error: Token '{' invalid key at column 33 of the expression [incluirNoCarrinho(mercadoria); {{mercadoria.show}} = true;] starting at [{mercadoria.show}} = true;].