cartItemJSON = [] as any[];
parseToJsonCartItems(cartItemJSON: any) {
this.cartItems.map(el => {
// console.log(el);
let cartItemJSON = (JSON.parse(JSON.stringify(el)));
console.log("TO JSON")
console.log(cartItemJSON);
return cartItemJSON;
})
}
cartItemJSON = [];
ngOnInit(): void {
this.cartItems = this.cartService.getCartItems();
this.parseToJsonCartItems();<img src="https://sun9-53.userapi.com/impg/z8Feo1iSa6lzlWiPKpw1GSjoadB9XPL-40eGgw/A_o0hb7EQFM.jpg?size=775x582&quality=96&sign=47e3524c655fbed7ae53c99a51d15092&type=album" alt="image"/>
}
parseToJsonCartItems(cartItemJSON : any) {
this.cartService.parseToJsonCartItems( cartItemJSON);
}
<button (click)="parseToJsonCartItems()">TO JSON</button>
<div>
cartItemJSON {{cartItemJSON}}
</div>
<a [title]="product.name + ' ' + product.productId" [routerLink]="['/products', product.productId - 1]">
{{ product.name }} <br>
productId -{{product.productId}}
</a>
export const products = [
{
productId: 1,
name: 'Phone XL',
price: 799,
description: 'A large phone with one of the best screens'
},
{
productId: 2,
name: 'Phone Mini',
price: 699,
description: 'A great phone with one of the best cameras'
},
{
productId: 3,
name: 'Phone Standard',
price: 299,
description: ''
}
];