Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I like to collect data from an android app and store them into sqlite DB - no problem so far. But now I want to list these data using AngularJS, ng-repeat command. I take the data from the DB via db.transaction(function(tx) tx.execSql...) but now how to format the data rows so that ng-repeat can read them ? I tried an array of objects, I tried building a JSON string - both not working, I got a ngRepeat error.

var app = angular.module('demo',[]);
app.controller("MainController", function($scope){
    // gets the tasks from the DB as json object
    db.transaction(function(tx){           
        tx.executeSql("SELECT task,task_detail,task_date FROM task", [],    
        function(tx, rs){    
            var rows = rs.rows;
            if (rows.length>0) {
                var json_arr =  [];  
                for(var i = 0; i < rows.length; i++) {
                    var row = rows.item(i);
                    var obj = {task: row.task,detail:row.task_detail,datum:row.task_date};
                    json_arr.push(obj);
                }                         
            }    
            var json_str = JSON.stringify(json_arr);
            alert("json_str: "+ json_str);  // WORKING !
            sessionStorage.tasks = json_arr; // to get result out of db.transaction...
            })  
        });  // end db.transaction
        $scope.tasks = sessionStorage.tasks;

-> when i display {{tasks}} it appears as: [object,object] and ng-repeat doesnt work

Otherwise if i use the stringified json, it displays correctly in {{tasks}} but ng-repeat causes again error.

Another real "dirty" way to get the result of the query into $scope is the sessionStorage thing - I dont like it this way but I cant see another possibility to set the $scope variable to the JSON (or whatever) result of the DB query. Maybe someone has a better idea ? ;)

Any ideas ? Thanks a lot, Chris

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.