Imran Imran - 1 year ago 93
AngularJS Question

How to read array object in angularjs

I got this array objects to be read:

enter image description here

These was my sample codes:

$scope.obj_qst_local_study_main = tbl_qst_local_study_main.all();
$scope.quesion_id_allocated = $scope.obj_qst_local_study_main[0];
console.log('----------all objects----------');
console.log('-----------one object-----------');

When I used:


The result was:

My angularjs services:

.service('tbl_qst_local_study_main', function($cordovaSQLite, DATABASE_LOCAL_NAME){
var self = this;
var qst_local_study_main_array = [];
self.all = function() {
var db = $cordovaSQLite.openDB({name: DATABASE_LOCAL_NAME,location:'default'});
$cordovaSQLite.execute(db, "SELECT * FROM qst_local_study_main")
.then(function (res) {
console.log('--------Successfully read from qst_local_study_main---------');
for (var i = 0; i < res.rows.length; i++) {
function (err) {
return qst_local_study_main_array;

Answer Source

Your service should return a Promise. This is a super common case, because (don't be offended please) people do not understand how Promises work.

Please search the internet for an article, like this one:

tl;dr Your service should return a Promise. In your case $cordovaSQLite.execute Then you can correctly handle the response by chaining thens. You also do not need the timeout. Using a timeout is super bad here!

  .then(function(result) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download