I am calling the data from listItems.push(res.rows.item(i).name); to a list by ng-repeat. so that i got a list of names that are present in SQLite.
This is my controllers.js
$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);
}, function (err) {
alert(err);
console.error(err);
});
$scope.getAllLists();
};
$scope.getAllLists = function () {
var listItems= [];
var query = "SELECT * FROM List";
$cordovaSQLite.execute($cordovaSQLite.openDB({ name: "Bd_DB.db" }), query).then(function (res) {
if (res.rows.item(0).name !="") {
for (var i = 0; i < res.rows.length; i++) {
listItems.push(res.rows.item(i).name);
}
}
});
}
I have tried , and but it is not showing any kind of list. i don't know, what i m doing wrong. please tell me the right code. Thanks This is my Html:
<div class="bar bar-header">
<button class="button icon-left ion-chevron-left button-clear button-dark" ng-click="closeModal()" ></button>
<h1 class="title">Your List</h1>
<button class="button" ng-click="createListPopup()"> Create List</button>
</div>
My ToDo List
<ion-content>
<div ng-repeat= "name in listItems">
{{item.name}}
</div>
</ion-content>
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>