javascript - ngStorage: retrive data with variable key -


i need help...

i need retrieve data localstorage ngstorage angular's plugin...

if write

$localstorage.temp = [{ name: "jhon", lastname: "pitt"}]; var myvar = $localstorage.temp; 

this fine.... if write

var str = 'temp'; $localstorage.temp = [{ name: "jhon", lastname: "pitt"}]; var myvar = $localstorage.[str]; // doesn't work myvar = $localstorage.str; // doesen't retrieve nothing cause there's no key 'str' in local storage 

if write this

var myvar = json.parse(window.localstorage.getitem(str)); 

it works, need use $localstorage how can solve problem? need much...

try in working plunker

you close, had syntax error on $localstorage.

try:

var str = 'temp'; $localstorage.temp = [{ name: "jhon", lastname: "pitt"}]; var myvar = $localstorage[str]; // remove . 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -