import { HttpClient } from '@angular/common/http'; import { THIS_EXPR } from '@angular/compiler/src/output/output_ast'; import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { Cart } from '../models/cart'; @Injectable({ providedIn: 'root' }) export class CartService { private _url : String = "http://localhost:8004/cart"; constructor(private _http : HttpClient) { } public addCartItem(item:Cart) { this._http.post(this._url+"/addCartItem",item); // console.log(item); } public showCart():Observable { return this._http.get(this._url+"/showCart"); } // public cartListItem: any=[] // public productList = new BehaviorSubject([]) // public addOrder(cart:Cart) // { // this._http.post(this._url+"/addCart",cart) // } // getProducts() // { // return this.productList.asObservable(); // } // setProduct(product:any) // { // this.cartListItem.push(...product); // this.productList.next(product); // } // addtoCart(product:any) // { // this.cartListItem.push(product); // this.productList.next(this.cartListItem) // this.getTotalPrice(); // // console.log(this.cartListItem); // } // getTotalPrice():number{ // let grandTotal=0; // this.cartListItem.map((a:any)=>{ // grandTotal+=a.productprice; // }) // return grandTotal; // } // removeCartItem(product:any) // { // this.cartListItem.map((a:any,index:any)=>{ // if(product.productid === a.productid) // { // this.cartListItem.splice(index,1); // } // }) // this.productList.next(this.cartListItem); // } // removeAllCart() // { // this.cartListItem=[] // this.productList.next(this.cartListItem); // } }