Reputation: 128
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
$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) $scope.tasks.push({title: res, completed: false});
})
};
Upvotes: 1
Views: 1070
Reputation: 309
You need to save it using localStorage like this:
$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));
})
};
Then in your controller you need to retrieve them
$scope.readTasks = function() {
for (var a in localStorage) {
$scope.tasks.push(JSON.parse(localStorage[a]));
}
};
In your view you can call the function like this:
<ion-content ng-init="readTasks()">
Upvotes: 1
Reputation: 113
You need to use LocalStorage. See if it's helpful: http://learn.ionicframework.com/formulas/localstorage/
Upvotes: 1