I am trying to make an angular2 cart (TS)
import {Injectable} from 'angular2/core'; import {Cart} from './product'; //interface id: Number; name: String @Injectable() export class ProductService { public products; public cart : Cart[] = []; addToCart(products: Object) { console.log('product=',products) this.cart.push(this.products); console.log('cart=',this.cart); }
When I click products in a method, I get
product= Object {id: 13, name: "Bombasto"}
but in
console.log('cart=',this.cart);
I have "undefined". Why?
source share