Issue
I have trying to refresh the view with the scope within after deleting a row on my SQLite cordova plugin for hours but have no luck.
Code :
$scope.remove = function() {
var x = document.getElementById("name").textContent;
$cordovaSQLite.execute(db, 'DELETE from table WHERE name=?', [x])
.then(function(res) {
var index = $scope.listItems.indexOf(x);
$scope.listItems.splice(index, 1);
}, function(error) {
console.log(error.message);
})
};
The delete was a success but leave me a blank page, to do refresh on my Ionic Platform app i have to go to other page than go back.
Other Code:
$scope.showConfirm = function () {
var x = document.getElementById("name").textContent;
var confirmPopup = $ionicPopup.confirm({
title: 'Deleting Journal Entry',
template: 'Are you sure you want to delete this item ?'
});
confirmPopup.then(function (res) {
if (res) {
var query = "DELETE FROM chocolates where name = ?";
$cordovaSQLite.execute(db, query, [x]);
$state.go($state.current, $stateParams, {reload: true, inherit: false});
console.log(x);
} else {
console.log('You are not sure');
};
});
};
This code also a success for deleting the row in my database, but the refresh function not working. The same as code before I have to go to other page and comeback to see the updated view.
have tried many answers from alternative 1 and alternative 2
Solution
After spending days debugging and reading, finally find the solution !
if (res) {
$ionicPlatform.ready(function () {
$scope.chocolates = [];
var query = "DELETE FROM chocolates where name = ?";
$cordovaSQLite.execute(db, query, [x]);
$cordovaSQLite.execute(db, 'SELECT * FROM chocolates ORDER BY choc_id DESC LIMIT 1', []).then(function (res) {
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
$scope.chocolates.push(res.rows.item(i));
}
}
}, function (err) {
console.error(err);
});
$scope.$apply();
});
} else {
console.log('You are not sure');
};
So far this is the cleaner solution, if no one comes up with a better idea, i will accept my own answer. Hopefully will help someone out there too.
Answered By - Jamal A N
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.