Factory module (Service)

angular.module('tutorialApp', []) 
.factory('Cart', function() { 
    var items = []; 
    return { getItems: function() { 
          return items; 
          }, 
          addArticle: function(article) { 
          items.push(article); 
          }, 
          sum: function() { 
                 return items.reduce(function(total, article) { return total + article.price; }, 0); } }; })

Dann dem $scope zuweisen:
.controller('ArticlesCtrl', function($scope, $http, Cart){ $scope.cart = Cart;
//... usw

Dann im doom verwenden:
<td><a href  ng-click="cart.addArticle(article);" >Hinzufügen</a></td>

Schreiben Sie einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert