From the ionic formulas page. I don’t get this bit:
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
I know it creates a get() method on $localstorage but I’m having some trouble getting it working and it’s because I don’t understand it.
If I use this
$localstorage.get('gender');
what happens if there is nothing stored? It looks like the method get()s the value from localStorage OR gets the defaultValue.
So if I do this:
get: function(key, defaultValue) {
return $window.localStorage[key] || 0;
},
I should get 0 as my default when nothing is stored, yes? Or do I have to do something else?
I’m trying to use this to store the user gender. I initialise it like this:
$scope.usergender = $localstorage.get('storeGender');
console.log("Usergender on initialise is", $scope.usergender);
and then store it like this:
changeGender = function(){$localstorage.set('storeGender',$scope.usergender)
console.log("Usergender is now", $scope.usergender);
}
My html looks like this:
<div class="item range range-assertive">
<i class="icon ion-male"></i> Male
<input type="range" name="gender" min="0" max="1" ng-model="usergender" onChange="changeGender()">
Female <i class="icon ion-female"></i>
</div>
At the moment all I get in the console is:
Usergender on initialise is undefined.
and this remains this way even after I use the range slider to try and change things. I’ve tried using ng-change and get the same thing.
Help?