Ionic LocalStorage

时间:2016-02-12 22:09:14

标签: javascript angularjs ionic-framework

I'm building an app at the moment, where you have a To Do List. These Task should be saved. I don't know why it doenst work :( Every time you click on Create Task the task should automatically be saved. And every time you open the app it should be displayed. Here is the Popup with the Create task button

Popup

[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User32.dll")]
static extern int ReleaseDC(IntPtr hwnd, IntPtr dc);

[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

IntPtr primary = GetDC(IntPtr.Zero);
int DESKTOPVERTRES = 117;
int DESKTOPHORZRES = 118;
int actualPixelsX = GetDeviceCaps(primary, DESKTOPHORZRES);
int actualPixelsY = GetDeviceCaps(primary, DESKTOPVERTRES);
ReleaseDC(IntPtr.Zero, primary);

2 个答案:

答案 0 :(得分:0)

您需要使用LocalStorage。看看它是否有用:http://learn.ionicframework.com/formulas/localstorage/

答案 1 :(得分:0)

您需要使用localStorage保存它,如下所示:

$scope.newTask = function() {
  $ionicPopup.prompt({
    title: "New Task",
    template: "Enter Task:",
    inputPlaceholder: "What do you need to do?",
    okText: 'Create Task'
  }).then(function(res) {    // promise 
    if (res) 
       var randomNumber = Math.floor((Math.random() * 100) + 1);
       var task = {title: res, completed: false};
       window.localStorage.setItem("Task" + randomNumber, JSON.stringify(testObject));

  })
};

然后在你的控制器中你需要检索它们

$scope.readTasks = function() {
   for (var a in localStorage) {
      $scope.tasks.push(JSON.parse(localStorage[a]));
   }
};

在您的视图中,您可以像这样调用函数:

 <ion-content ng-init="readTasks()">