Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <h2>Shopping Card Example</h2>
  2. <div ng:controller="CartForm">
  3. <table class="table">
  4. <tr>
  5.  
  6. <th>Description</th>
  7. <th>Qty</th>
  8. <th>Cost</th>
  9. <th>Total</th>
  10. <th></th>
  11. </tr>
  12. <tr ng:repeat="item in invoice.items">
  13. <td><input type="text" ng:model="item.description"class="input-small"></td>
  14. <td><input type="number" ng:model="item.qty" ng:required class="input-mini"></td>
  15. <td><input type="number" ng:model="item.cost" ng:required class="input-mini"></td>
  16. <td>{{item.qty * item.cost | currency}}</td>
  17. <td>
  18. [<a href ng:click="removeItem($index)">X</a>]
  19. </td>
  20. </tr>
  21. <tr>
  22. <td><a href ng:click="addItem()" class="btn btn-small">add item</a></td>
  23. <td></td>
  24. <td>Total:</td>
  25. <td>{{total() | currency}}</td>
  26. </tr>
  27. </table>
  28. </div>
  29.  
  30. function CartForm($scope) {
  31. $scope.invoice = {
  32. items: [{
  33. qty: 10,
  34. description: 'item',
  35. cost: 9.95}]
  36. };
  37.  
  38. $scope.addItem = function() {
  39. $scope.invoice.items.push({
  40. qty: 1,
  41. description: '',
  42. cost: 0
  43. });
  44. },
  45.  
  46. $scope.removeItem = function(index) {
  47. $scope.invoice.items.splice(index, 1);
  48. },
  49.  
  50. $scope.total = function() {
  51. var total = 0;
  52. angular.forEach($scope.invoice.items, function(item) {
  53. total += item.qty * item.cost;
  54. })
  55.  
  56. return total;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement