javascript - Error with $cordovaSQLite plugin on ionic -
i want query's on db ... problem when run app, screen blank, don't why. read in ionic.platform.ready()
, run perfect when want use in controller wrong when blank screen...
that's code in .ready()
function:
var primera=[]; var contador=0; var citas = window.sqliteplugin.opendatabase({name: "citas.db", location: 'default'}); var query= "select * usuario codigo=?"; $cordovasqlite.execute(citas, query, [0]).then(function(data){ contador=data.rows.length; (var = 0; < data.rows.length; i++) { var datos={ codigo:'', telefono:'', password:'', status:'' }; datos.codigo = data.rows.item(i).codigo; datos.telefono = data.rows.item(i).telefono; datos.password= data.rows.item(i).password; datos.status= data.rows.item(i).status; primera.push(datos); }//fin del //alert("select activo de app"); }, function(err){ alert('error al insertar datos primarios'); });//fin del execute
that code in controller:
var citas=window.sqliteplugin.opendatabase({name: 'citas.db', location: 'default'}); var query= "select * usuario codigo=?"; $cordovasqlite.execute(citas, query, [0]).then(function(data){ alert("entro en execute"); (var = 0; < data.rows.length; i++) { var datos={ codigo:'', telefono:'', password:'', status:'' }; datos.codigo = data.rows.item(i).codigo; datos.telefono = data.rows.item(i).telefono; datos.password= data.rows.item(i).password; datos.status= data.rows.item(i).status; $scope.sesion.push(datos); }//fin del alert('descarga completada'); if($scope.sesion[0].status=='activo'){ $scope.tlf_login=$scope.sesion[0].telefono; $scope.pass_login=$scope.sesion[0].password; buscarpersona(); } }, function(err){ alert('error al recuperar datos'); });//fin del execute
i resolve that, do? well.. procedure convert function , use delay $timeout before execute function, guess problem native function sqlite device should ready use that.. in many word's:
$timeout(function() { $scope.verificar_sesion(); }, 500);
Comments
Post a Comment