Display data from sqlite to List


Could you some one help to display data stored in sqlite table to list using ng-repeat. This is working fine for json strings. however not working for sqlite.



what are you using for SQLite wrapper ? javascript ?
check the object structure returned by the SQLite

post the code for better understanding of the code


Hi Harshit,
I can’t check the object structure since I am executing it in emulator. However I converted sqllite data to json form usingstringify and assigned it to scope variable however the code is not working as ui is not rendering. I have checked the logs which shows stringify scope variable.


You should not be assigning the string to scope variable, directly assign the object returned by the Cordova function and not the stringified string… If that still doesn’t work, please provide the code and the stringified string…


Hi Harshit,
here is my code
var countQuery = “select id,name,image_url,category,price from tblProduct”;
$cordovaSQLite.execute(LBdb, countQuery).then(function(result){
$scope.items = result.rows

however above code does not worked hence i stringified as below

if(result.rows.length > 0){
var itemsColl = [];
for (var i = 0; i < result.rows.length; i++) {
itemsColl[i] = result.rows.item(i);


        items = JSON.stringify(itemsColl);
        console.log("scope of items is " + items);
        return items;

this is also not working

HTML code is

item.name }}

{{ item.category}}

        <br />
        <h4 class="price"> {{ item.price }}</h4>
         <i class="icon ion-ios7-arrow-forward"></i>


can you stringify the result object and post the output ?

also on eclipse check the error you are getting in logcat console

also to access the object in array, u access it as follows


and not as result.rows.item(i);


Hi Harshit,

Finally got it working, earlier I have created separate file for db interaction and returning array from it still dont know why angular was not returning it might be some promise related issues.
Hence I moved code to controller and called function when angular loads, this is working now although as a workaround and not the way I want it.
First I need to understand asynchronous stuff and understand what a promise, deffer, digest and apply means then might be I will achieve what I want to

Thank for helping me out


1 Like

Hi Harshitgoel96,
I am facing the same problem here is my code.

.controller('databaseCtrl', function($scope, $cordovaSQLite){
      var db= $cordovaSQLite.openDB({name: "mydb.db"});
     var query=" SELECT * FROM song" ;

     $cordovaSQLite.execute(db, query, []).then(function(result) {
     if(result.rows.length >0){

    for(var i=0; i<result.rows.length; i++){
   console.log("####console######## NO results found #######"+"Table record #: ");
}, function(error){
1 Like

instead of




1 Like

Any updates on this? Are the codes working? Thank you in advance.


Just want to share this to you. I think this can help.

    indent preformatted text by 4 spaces

How about this? It is not working though
I need help in this too…

 $scope.select = function (lastname) {
        $scope.statusMessage = "Start Fetching "+ $scope.lname;
        var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
        $cordovaSQLite.execute(db, query, [$scope.lname]).then(function (res) {
            if (res.rows.length > 0) {
                for (var i = res.rows.length - 1; i <= 0; i++) {
                    // $scope.statusMessage = "SELECTED -> " + res.rows.item(i).firstname + " " + res.rows.item(i).lastname;
            } else {
                $scope.statusMessage = "No results found";
        }, function (err) {
1 Like

Thanks a Million. It works like charm.


It would be '$scope.results.push(result.rows.item(i)); Note: ‘item’ instead of ‘items’.

1 Like

I m trying to open my pre defined database in ionic…which i placed in www directory…but when ever i run the app i m unable to access tabels of my db so plz buddies if u have any solution plz help me out…i m unable to load my database…hope u got my problem…


Hallo every one, i have 2 problem to display data from sqlite.
1. How to insert data from json to sqlite
2. How to display sqlite data on listview

i have try the code above, but i still stack ?
any one can help me ?
thank you


Try with this example: https://github.com/jdnichollsc/Ionic-Starter-Template

Regards, Nicholls


how can i bind select query result to an array without for loop to improve my speed?



db.executeSql("SELECT * FROM usernameList", []).then((data) => {
            if (data.rows.length > 0) {

              for (var i = 0; i < data.rows.length; i++) {



        <ion-item *ngFor="let data of list_elements">