Skip to content
Loading
  • Laxmidhar Sahoo
    +1
    hi
     
    1. export class ShoppingCartComponent implements OnInit {    
    2. items: item[] = [];    
    3.    
    4. var item1 = new item ({  quantity: 1, product_name: 'abc' ,product_price: 20});  
    5.    
    6. this.items.push(item1);  
    7. localStorage.setItem('item', JSON.stringify(item1);    
    8.   
    9. onSubmit(quantity, product_name, product_price){    
    10.    
    11. var item2 = new item ({  quantity: quantity, product_name: product_name ,product_price: product_price});  
    12.      
    13. this.items.push( item2 );    
    14. }    
    15. }    
    16.   
    17. export class item {  
    18.     quantity: number;  
    19.     product_name: String;  
    20.     product_price: number;  
    21. }  
     
    +1
  • +1
    The Items array actually needs to be saved to localStorage. How do I push an array to localStorage?
    +1
  • +1
    Thanks, Laxmidhar Sahoo and Rajanikant Hawaldar
    +1
  • Laxmidhar Sahoo
    +1
    localStorage.setItem('items', JSON.stringify(this.items));
    +1
  • +1
    The solution was posted here: https://groups.google.com/forum/#!topic/angular/ROO8TCiw5Qw
    +1