JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-controller="CarrinhoController" ng-app>
<div ng-repeat="item in itens">
<span>{{item.nome}}</span>
<input ng-model="item.qtd" />
<span>{{item.preco | currency}}</span>
<span>{{item.preco * item.qtd | currency}}</span>
</div>
<div>Total: {{totalCarrinho() | currency}}</div>
<div>Desconto: {{conta.desconto | currency}}</div>
<div>Subtotal: {{subtotal() | currency}}</div>
</div>
JavaScript
function CarrinhoController( $scope ) {
$scope.conta = {};
$scope.itens = [
{nome: 'Produto #1', qtd: 7, preco: 3.95},
{nome: 'Produto #2', qtd: 10, preco: 12.95},
{nome: 'Produto #3', qtd: 6, preco: 6.95}
];
$scope.totalCarrinho = function() {
var total = 0;
for( var i = 0; i < $scope.itens.length; i++ ) {
total = total + $scope.itens[ i ].preco * $scope.itens[i].qtd;
}
return total;
};
$scope.subtotal = function() {
return $scope.totalCarrinho() - $scope.conta.desconto;
};
function calcularDesconto( newValue, oldValue, scope ) {
$scope.conta.desconto = newValue > 100 ? 10 : 0;
}
//$scope.$watch( $scope.totalCarrinho, calcularDesconto );
}