1
I managed with the help of Esmigol to solve one of the problems and I am insisting here because I did not find anything on the internet that can help me. There are few examples of what I need on the Internet. The line calculation is ok (quantity x unit value) plus the sum and subtraction of the Total Value I’m picking up. What I’m doing wrong [![
$scope.valorClaro = [
{id: 1, gb: 0, qtd: '', preco: 39.99, descricao: "Ligações Ilimitadas", operadora: "Tim"},
{
id: 2,
gb: 0.5,
qtd: '',
preco: 45.99,
descricao: "Ligações Ilimitadas + WhatsApp + SMS + Conteúdo Digital",
operadora: "Claro"
}
]
$scope.soma = 0;
$scope.multiplicaValor = function (index) {
index.totalLinha = index.qtd * index.preco;
angular.forEach($scope.valorClaro, function () {
$scope.soma += index.qtd * index.preco;
});
console.log(index.totalLinha);
}
<form name="formSimula">
<div class="card mt-3">
<div class="card-header font-weight-bold">
<img src="./dist/images/icon-claro.png"> Simulador Planos Claro
<span class="float-right" style="font-size: 30px;">{{soma | currency}}</span>
</div>
<table class="table table-hover mb-0" style="font-size: 0.875em;">
<thead>
<tr class="alert-warning d-flex">
<th class="text-center col-1">GB</th>
<th class="col-2">Valor</th>
<th class="col-5">Descrição</th>
<th class="col-2 text-center">Qtd Linhas</th>
<th class="col-2">Total</th>
</tr>
</thead>
<tbody>
<tr class="d-flex font-weight-bold font-open" ng-repeat="claro in valorClaro">
<td class="align-middle text-center col-1">{{claro.gb}}</td>
<td class="col-2 align-middle">{{ claro.preco | currency}}</td>
<td class="align-middle col-5">{{ claro.descricao}}</td>
<td class="align-middle col-2 text-center">
<input type="text" class="form-control form-control-sm text-center" ng-model="claro.qtd"
ng-change="multiplicaValor(claro)">
</td>
<td class="align-middle col-2">
<input type="text" class="form-control form-control-sm text-center"
value="{{claro.totalLinha | currency}}">
</td>
</tr>
</tbody>
</table>
</div>
</form>
Can you provide us with your HTML markup as well? At least this block is displayed in the image...
– Dinei
@Dinei includes HTML code
– Ricardo Chomicz
Your
ng-model
in theinput
has to make reference to the objectclaro
:ng-model="claro.preco"
– Sorack