I'm trying to do cart by angular2(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 push products in method I get
product= Object {id: 13, name: "Bombasto"}
but in
console.log('cart=',this.cart);
I have "undefined". Why?