var demoApp = angular.module('myApp', []);
demoApp.controller('QaController', function($scope, $http) {
$scope.total_amount = 0;
$scope.books = [
{id:1, name:'Book1', 'price':120},
{id:2, name:'Book2', 'price':199},
{id:3, name:'Book3', 'price':135}
];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<h2>Book Listing</h2>
<div ng-controller="QaController">
<!--<strong>Total Price : {{total_amount | currency}}</strong>-->
<hr />
<div ng-repeat="book in books" ng-init="total_amount = book.price + total_amount">
Name : {{book.name}} <br />
Price : {{book.price}}<hr />
</div>
<strong>Total Amount: {{total_amount | currency}}</strong>
</div>
</body>
I have posted my sample code. I want to sum total amount of price of my all books. Please check code snippet I have initialize my total_amount but my total_amount is showing $0.00 actually my sum amount is $454.00 please tell me how to SUM my books prices and show the result in view page?