diff --git a/www/js/controllers.js b/www/js/controllers.js index 5458c10..ec6a833 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -1,10 +1,12 @@ angular.module('starter.controllers', []) -.controller('DashCtrl', function($scope,$ionicPopup,$http) { +.controller('DashCtrl', function($scope,$ionicPopup,$http, $localstorage) { $scope.preis=""; $scope.name=""; $scope.freitext=""; + $scope.items=[]; + $scope.item=[]; $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) { var strResult = ""; diff --git a/www/js/services.js b/www/js/services.js index 73837bf..ac7c5b6 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -1,50 +1,19 @@ 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 { - all: function() { - return chats; + set: function(key, value) { + $window.localStorage[key] = value; }, - remove: function(chat) { - chats.splice(chats.indexOf(chat), 1); + get: function(key, defaultValue) { + return $window.localStorage[key] || defaultValue; }, - get: function(chatId) { - for (var i = 0; i < chats.length; i++) { - if (chats[i].id === parseInt(chatId)) { - return chats[i]; - } - } - return null; + setObject: function(key, value) { + $window.localStorage[key] = JSON.stringify(value); + }, + getObject: function(key) { + return JSON.parse($window.localStorage[key] || '{}'); } - }; -}); + } +}]); diff --git a/www/templates/tab-dash.html b/www/templates/tab-dash.html index b0be4e8..f9641b7 100644 --- a/www/templates/tab-dash.html +++ b/www/templates/tab-dash.html @@ -43,6 +43,10 @@
+