I must be doing this wrong. I'm trying to loop through all the key value pairs and then send that via a POST.
Expand|Select|Wrap|Line Numbers
- public postInfo() {
- for (let i = 0; i < localStorage.length; i++) {
- const key = localStorage.key(i);
- const headerDict = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'Access-Control-Allow-Headers': 'Content-Type',
- }
- const requestOptions = {
- headers: new HttpHeaders(headerDict),
- };
- this.http.post(this.url, key, requestOptions).subscribe(data => {
- console.log(data);
- });
- }
- }
Expand|Select|Wrap|Line Numbers
- addToCart(product: Product) {
- var sendJson = JSON.stringify(product.productID);
- var jsonData = JSON.stringify(product.productName)
- localStorage.setItem(sendJson, jsonData);
- }