angularjs - ionic framework with SQL lite -


i using ionic framework .

i implementing following steps

1) app runs . create db , table 2) use login, saving data mysql , go dashboard page

dbquery.insertcategory();  $state.go('app.dashboard'); 

dbquery factory .

.factory('dbquery', function ($http, $q, $cordovasqlite, localstorage) {      return {          insertcategory: function () {              $http({                  url: "http://mydoman.comcategory",                  method: 'get',                  withcredentials: true,              }).success((function (result) {                  var user_id = localstorage.get('user_id');                  var query = "insert or ignore categories (category_id, user_id, category_name,category_type) values (?,?,?,?)";                  var data = '';                  result.foreach(function (category) {                      $cordovasqlite.execute(db, query, [category.id,user_id, category.category_name, category.category_type]).then(function (res) {                          console.log("insertid");                      }, function (err) {                           console.dir(err);                      });                  });             }))          }, 

which working fine

on dashboard showing categories list , found nothing .

i did debugging , found insertion of categories taking time insert.

is there way 2 way data binding

thanks

why not use promise , redirect app.dashboard once success promise triggers?

example:

dbquery.insertcategory().then(function(result) {     $state.go('app.dashboard'); }, function(error) {     console.error(error); }); 

then in factory can have this:

.factory('dbquery', function ($http, $q, $cordovasqlite, localstorage) {      return {          insertcategory: function () {              var deferred = $q.defer();              $http({                  url: "http://mydoman.comcategory",                  method: 'get',                  withcredentials: true,              }).success((function (result) {                  var user_id = localstorage.get('user_id');                  var query = "insert or ignore categories (category_id, user_id, category_name,category_type) values (?,?,?,?)";                  var data = '';                  result.foreach(function (category) {                      iswaiting = true;                      $cordovasqlite.execute(db, query, [category.id,user_id, category.category_name, category.category_type]).then(function (res) {                          console.log("insertid");                          iswaiting = false;                      }, function (err) {                          console.dir(err);                          iswaiting = false;                      });                      while(iswaiting) {}                  });                  deferred.resolve("done");             }))             return deferred.promise;          }, 

a lot of did theory, should give idea. created boolean make sql commands synchronous. since synchronous, when loop ends, can return success promise.

there few other ways well. maybe move sql stuff own function , recursively enter it.

let me know if of works you.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -