I'm new to Angular and i'm trying to make a simple ecommerce where the user is able to add items to cart, view them and make a checkout.
So i have 3 components, the products list, cart and checkout and a cart service which manage all cart operations like adding items, removing and calculating the cart total.
I was wondering which would be the best solution to save the cart when the user closes the browser and reopen it as initially the user orders will be managed anonymously so without any registrations.
Is still the best solution to use localstorage and to use cookies when there will be a registration?
any data saved on client may change or delete by the user ,the best option is to store the data on database at the service as temporary and get the value later when the app launch again or it's open in different browser.
localStorge will be a grate place over sessionStorgae because data in localStorage doesn't expire
example cart data service with localStorge demo
sessionStorage will clear when the page session ends.
A page session lasts as long as the browser is open, and survives over page reloads and restores