Hi I’m trying to follow the ToDo example with a little variation, using SQLservice.
But the function to reorder the taks list is not working, here is my code:
angular.module('todo', ['ionic','todo.services'])
.controller(‘TodoCtrl’, function($scope, $ionicModal, $ionicPopup, SQLService) {
SQLService.setup();
$scope.loadTask = function() {
SQLService.all().then(function (results) {
$scope.tasks = results;
});
}
$scope.loadTask();
// Create and load the Modal
$ionicModal.fromTemplateUrl(‘new-task.html’, function(modal) {
$scope.taskModal = modal;
}, {
scope: $scope,
animation: ‘slide-in-up’
});
// Open our new task modal
$scope.newTask = function() {
$scope.taskModal.show();
};
// Close the new task modal
$scope.closeNewTask = function() {
$scope.taskModal.hide();
};
// Called when the form is submitted
$scope.createTask = function(task) {
SQLService.set(task.title);
$scope.loadTask();
$scope.taskModal.hide();
task.title = “”;
};
$scope.onItemDelete = function(taskid) {
$ionicPopup.confirm({
title: ‘Confirm Delete’,
content: ‘Are you sure you want to delete this task?’
}).then(function(res) {
if(res) {
SQLService.del(taskid);
$scope.loadTask();
}
});
};
$scope.onItemEdit = function(taskid) {
$ionicPopup.prompt({
title: 'Update Task',
subTitle: 'Enter new task'
}).then(function(res) {
SQLService.edit(res, taskid);
$scope.loadTask();
});
};
$scope.moveItem = function(task_id, fromIndex, toIndex) {
$scope.tasks.splice(fromIndex, 1);
$scope.tasks.splice(toIndex, 0, task_id);
};
});
This is the section of my index.html where I call the function moveItem :
<ion-item ng-show="tasks.length" ng-repeat="task in tasks" item="task">
{{task.task_id}} {{task.task_name}}
<ion-delete-button class="ion-minus-circled" ng-click="onItemDelete(task.task_id)"></ion-delete-button>
<ion-option-button class="button-assertive" ng-click="onItemEdit(task.task_id)">Edita</ion-option-button>
<ion-reorder-button class="ion-navicon" on-reorder="moveItem(task.task_id, $fromIndex, $toIndex)"></ion-reorder-button>
</ion-item>
Any idea?
Thank you in advance