I've tried to follow examples here, I know there might be a few different ways of adding objects to an array in $localstorage and not overwriting it but I'm failing to find at least one of them.
**
TypeError: $scope.sTempLoc.push is not a function
**
.controller('AddWfhCtrl', function($scope, $http, $rootScope, $localStorage, $ionicLoading, $ionicHistory, $cordovaGeolocation,$ionicPopup, focus){
$scope.saveWfhLocation = function (){
$scope.sTempLoc = [];
if(typeof $scope.uCurLocDtls.uCuWfhLocName != "undefined" || $scope.uCurLocDtls.uCuWfhLocName != ""){
if(angular.isDefined($localStorage.userWFHLocs)){
$scope.sTempLoc = $localStorage.userWFHLocs;
$scope.sTempLoc.push($scope.uCurLocDtls);
$localStorage.userWFHLocs = $scope.sTempLoc;
}else{
$localStorage.userWFHLocs = $scope.uCurLocDtls;
}
$ionicHistory.goBack();
}
}
})
I recommend you give $localForage a try because I think it is better and easier to work with than $localStorage.
Reference: https://github.com/localForage/localForage