angular - Cordova SQLite Return a Promise? -


consider method in angular service:

    select : function(table) {         window.sqliteplugin.opendatabase({             name: 'smartlab.db',             location: 'default'         }, function success(db) {             var defer = window.q.defer();              console.dir(defer);              db.executesql('select * ' + table, [], function success(rows) {                 var resp = [];                  for(var = 0; < rows.rows.length; i++) {                     resp.push(rows.rows.item(i));                 }                  defer.resolve(resp);              }, defer.reject)         }, function error(err) {          })     } 

i calling service in following way:

databaseservice.select(tbl_name).then(function(rows) {   // logic goes here }); 

the error is:

uncaught typeerror: cannot read property 'then' of undefined 

i have never used q before familiar promises, jump out being inherently wrong? is...

you never returning promise defered object (click here more)

select : function(table) {     var defer = window.q.defer();      window.sqliteplugin.opendatabase({         name: 'smartlab.db',         location: 'default'     }, function success(db) {           console.dir(defer);          db.executesql('select * ' + table, [], function success(rows) {             var resp = [];              for(var = 0; < rows.rows.length; i++) {                 resp.push(rows.rows.item(i));             }              defer.resolve(resp);          }, defer.reject)     }, function error(err) {      });      return defer.promise; } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -