StackOverflow_24208265: watch-not-updating-in-ng-repeat
Illustration of answer to http://stackoverflow.com/questions/24208265/watch-not-updating-in-ng-repeat.
by ExpertSystem
HTML
<script src="http://code.angularjs.org/1.2.16/angular.min.js"></script>
<div ng-controller="myCtrl">
Unit price:
<input type="number" ng-model="unit_price" />
<br />
Quantity:
<input type="number" ng-model="quantity" />
<hr />
Total: {{total}}
</div>
JavaScript
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.unit_price = 0;
$scope.quantity = 0;
$scope.$watchCollection('[unit_price, quantity]', function(newValues) {
$scope.total = $scope.unit_price * $scope.quantity;
});
});