LocalStorage geadded

This commit is contained in:
Carsten Hilmer 2016-01-08 00:03:26 +01:00
parent 4e31f6eda6
commit 23a833a31b
3 changed files with 30 additions and 44 deletions

View File

@ -1,10 +1,12 @@
angular.module('starter.controllers', []) angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http) { .controller('DashCtrl', function($scope,$ionicPopup,$http, $localstorage) {
$scope.preis=""; $scope.preis="";
$scope.name=""; $scope.name="";
$scope.freitext=""; $scope.freitext="";
$scope.items=[];
$scope.item=[];
$scope.validate = function() { $scope.validate = function() {
@ -18,6 +20,17 @@ angular.module('starter.controllers', [])
}; };
$scope.loaddata = function() {
$scope.items=$localstorage.getObject('items');
alert(JSON.stringify($scope.items));
};
$scope.savedata = function() {
$scope.item={name: $scope.name, freitext: $scope.freitext, rosen: $scope.preis, bild: "test"};
alert(JSON.stringify($scope.item));
$scope.items.push($scope.item);
$localstorage.setObject('items',$scope.items);
};
function successBuyHandler (result) { function successBuyHandler (result) {
var strResult = ""; var strResult = "";

View File

@ -1,50 +1,19 @@
angular.module('starter.services', []) angular.module('starter.services', [])
.factory('Chats', function() {
// Might use a resource here that returns a JSON array
// Some fake testing data
var chats = [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];
.factory('$localstorage', ['$window', function($window) {
return { return {
all: function() { set: function(key, value) {
return chats; $window.localStorage[key] = value;
}, },
remove: function(chat) { get: function(key, defaultValue) {
chats.splice(chats.indexOf(chat), 1); return $window.localStorage[key] || defaultValue;
}, },
get: function(chatId) { setObject: function(key, value) {
for (var i = 0; i < chats.length; i++) { $window.localStorage[key] = JSON.stringify(value);
if (chats[i].id === parseInt(chatId)) { },
return chats[i]; getObject: function(key) {
} return JSON.parse($window.localStorage[key] || '{}');
}
return null;
} }
}; }
}); }]);

View File

@ -43,6 +43,10 @@
<div class="col col-50"><button class="button button-full button-small icon-left ion-social-euro button-custom" ng-disabled="!$parent.preis || !$parent.freitext || !$parent.name" ng-click="buyRose()">Jetzt Kaufen</button></div> <div class="col col-50"><button class="button button-full button-small icon-left ion-social-euro button-custom" ng-disabled="!$parent.preis || !$parent.freitext || !$parent.name" ng-click="buyRose()">Jetzt Kaufen</button></div>
</div> </div>
<div class="row">
<div class="col col-50"><button class="button button-full button-small icon-left ion-image button-custom" ng-disabled="!$parent.preis || !$parent.name || !$parent.freitext" ng-click="loaddata()">Laden</button></div>
<div class="col col-50"><button class="button button-full button-small icon-left ion-social-euro button-custom" ng-disabled="!$parent.preis || !$parent.freitext || !$parent.name" ng-click="savedata()">Speichern</button></div>
</div>
</div> </div>