sqlite selected data not showing to ng-repeat
sqlite transaction is synchronous, so in the create list, you have to call the getList in the success callback of the execute:like: $scope.createList = function () {
var value1 = document.getElementById("List").value;alert(value1);var db = $cordovaSQLite.openDB({ name: "Bd_DB.db" });var query = "INSERT INTO List (name) VALUES (?)";$cordovaSQLite.execute(db, query, [value1]).then(function (res) { console.log("insertId: " + res.insertId); $scope.getAllLists();}, function (err) { alert(err); console.error(err);});
};
Also, in the getAllLists, the function will end regardless of the status of the .execute, so you have to bind to a variable which be set inside the success callback.
$scope.listItems= [];
$scope.getAllLists = function () {
var query = "SELECT * FROM List";$cordovaSQLite.execute($cordovaSQLite.openDB({ name: "Bd_DB.db" }), query).then(function (res) { $scope.listItems= []; if (res.rows.item(0).name !="") { for (var i = 0; i < res.rows.length; i++) { listItems.push(res.rows.item(i).name); } $scope.$apply(); }}
Finally, you have to made $scope.$apply() to reflect the result to the view.
Try changing var listItems= []
to a scope variable
$scope.listItems = [];....$scope.listItems.push({name:'item 1'})
and then in your view:
<ion-content> <div ng-repeat= "item in listItems"> {{item.name}} </div></ion-content>