19
การคำนวณผลรวมขององค์ประกอบที่ซ้ำใน AngularJS ng-repeat
ng-repeatสคริปต์ด้านล่างแสดงรถเข็นร้านใช้ สำหรับแต่ละองค์ประกอบในอาร์เรย์จะแสดงชื่อรายการจำนวนและผลรวมย่อย ( product.price * product.quantity) วิธีที่ง่ายที่สุดในการคำนวณราคารวมขององค์ประกอบซ้ำคืออะไร? <table> <tr> <th>Product</th> <th>Quantity</th> <th>Price</th> </tr> <tr ng-repeat="product in cart.products"> <td>{{product.name}}</td> <td>{{product.quantity}}</td> <td>{{product.price * product.quantity}} €</td> </tr> <tr> <td></td> <td>Total :</td> <td></td> <!-- Here is the total value of my cart --> </tr> </table>