arrays


localstorage initially returns assigned type, then type Object


I am developing a shopping cart which enables users to add items of type "Product" to basket. When an item is initially added it is of type "Product", however when another item(second item) is added to the Array() array, it is of type "Object" from then on. This may not make a lot of difference during manipulation, however i'd rather keep the types consistent. Someone please point out where im going wrong, much appreciated.
constructor(private _http: Http) {
localStorage.setItem("cart", JSON.stringify(new Array<Product>()));
}
GetCartProducts() {
let storage:string = localStorage.getItem("cart");
return <Array<Product>>((storage) ? JSON.parse(storage) : new Array<Product>());
}
AddProduct(product: Product) {
let items = <Array<Product>>this.GetCartProducts();
console.log(items);
items.push(<Product>product);
console.log(items);
localStorage.setItem("cart", JSON.stringify(<Array<Product>>items));
}

Related Links

Calculate the derivative of a vector
How to assign excel cell with string to array value in visual basic?
python 3 read array (list?) into new values
Decrypt an array of strings in vb.net
bash array with new line as IFS
create new object in array (which is in a object which is in an array which is document) in meteor/mongodb
Initializing an array of records in VHDL
Perl Array and Hash references Handling
Separating digits in decimal representation of integer
How do I return an array from an array function using groovy?
Perl - Reading two files to compare contents
Accessing hash values(arrays) in Perl
C - Errors in header file
Elasticsearch Term Filter on Array
Magento 1.7 left navigation category sort order alphabetically
Collection of Classes - Array property not populating correctly

Categories

HOME
sql-server
performancecounter
ocaml
amazon-product-api
command
docker-windows
codeblocks
currency
xlsx
abcpdf
data-analysis
equalizer
rapidjson
sql-tuning
zope
riak-ts
saiku
chocolatey
google-api-java-client
flexlm
device-detection
aws-cognito
qsub
philips-hue
pdfsharp
net-snmp
partial-application
spring-profiles
shapes
geopy
fabric-digits
mapguide
pace
autocompletetextview
meta-raspberrypi
control-flow-graph
proof
defold
ti-basic
seamless-immutable
google-maps-ios
cdk
static-code-analysis
selenium-firefoxdriver
iron.io
polar-coordinates
onresume
keycode
atlassian-crowd
nsfetchedresultscontrolle
hspec
freetype2
asteriskami
gherkin
clob
asp.net-mvc-partialview
financial
usb-drive
handlebars.java
matcaffe
jericho-html-parser
response-headers
sevenzipsharp
pyrocms
rx-groovy
ubercart
uos
callstack
word-2013
google-earth-plugin
jai
ultrawingrid
qtestlib
ibmsbt
hidden-field
io.js
wss
jstack
json-patch
android-json-rpc
fogbugz-api
image-zoom
ng-hide
leptonica
dllexport
threadx
localtime
argb
xslkey
appfog
text-services-framework
datacontract
associative
for-xml-path
search-path
nagle
symbol-server
asp.net-mvc-controller
kpi
winsnmp
handheld
weborb

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App