title: Angular 2 - call function after change
body: <p>I want to call the <code>getCartSum()</code> function after the <code>addToCart(cartItem)</code> added the item to the cart so I receive the new "total" value of the cart.</p>
  
  <p>here is my Service:</p>
  
  <pre><code>public cartItems: any[] = [];
  public total: number;
  
  constructor() {}
  
  addToCart(cartItem) {
      this.cartItems.push(cartItem);
  }
  
  getCart() {
      return this.cartItems;
  }
  
  getCartSum() {
      this.total = 0;
      if (Object.keys(this.cartItems).length != 0) {
          for (var x of this.cartItems) {
              this.total += x.product.price;
          }
          return this.total;  
      }
      return this.total;
  }
  </code></pre>
  
  <p>and here my ShoppingCart Component:</p>
  
  <pre><code>export class ShoppingCart  {
  public title: string = "ShoppingCart";
  public cartItems: any[];
  public total: number;
  
  constructor(private _cartService: CartService) {
      this.cartItems = this._cartService.getCart()
      this.total = this._cartService.getCartSum()
  }
  
  getCartSum() {
      this.total = this._cartService.getCartSum()
  }
  }
  </code></pre>