Created
October 12, 2017 07:35
-
-
Save tkssharma/685ffe17a9806c9c7be92ff255d02d94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class cartService { | |
constructor(private httpclient : HttpClient) {} | |
private cartSubject = new Subject<CartState>(); | |
Products : product[]= []; | |
CartState = this.cartSubject.asObservable(); | |
addProduct(_product:any) { | |
console.log('in service'); | |
this.Products.push(_product) | |
this.cartSubject.next(<CartState>{loaded: true, products: this.Products}); | |
} | |
removeProduct(id:number) { | |
this.Products = this.Products.filter((_item) => _item.id !== id ) | |
this.cartSubject.next(<CartState>{loaded: false , products: this.Products}); | |
} | |
getAllProducts() : Observable <any> { | |
return this.httpclient.get(url).map((res : Response) => res.json()) | |
.catch((error : any) => Observable.throw('Server error')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment