I have a problem when trying to implement the SQLite plugin from the official ngCordova website, and I can not find out what it is; In the browser console I do not see any errors when I start the application using ionic serve , only when you try to use $ cordovaSQLite to create the database, obviously at this time if an error appears, because only this command works on the device.
The main view of the application appears blank, therefore it does not work; I have researched the internet and they recommended me to see the errors from the console using the adb command.
-
Crosswalk Plugin
-
Brackets editor
-
Windows 10
-
Cordova Cli 6.0.0
-
Ionic Cli 1.7.14
-
Node Version 5.5.0
I found a post in the official forum of the page where they talk about the problem, here I leave the link Error .
This is the code
app.js
'angular.module('unicesarApp', ['ionic', 'ngCordova'])
.run(Inicio);
Inicio.$inject = ['$ionicPlatform'];
function Inicio($ionicPlatform) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
});
};
login.js
angular.module('unicesarApp', ['ionic', 'historialApp', 'ngCordova'])
.controller('formulario', formulario)
.service('obtenerDatos', obtenerDatos)
.config(config);
formulario.$inject = ['$scope', 'obtenerDatos', '$state', '$timeout', '$cordovaSQLite'];
function formulario($scope, obtenerDatos, $state, $timeout, $cordovaSQLite){
$scope.login = function(){
var datos, datosRespuesta;
datos = {
Usuario: $scope.usuariotxt,
Password: $scope.passwordtxt
};
if(datos.Usuario == undefined && datos.Password == undefined){
$scope.respuesta = "Los campos estan vacios";
}else{
$scope.respuesta = "Solicitando informacion";
obtenerDatos.Autenticacion(datos).then(function(response) {
if(response.data) {
datosRespuesta = response.data;
if (datosRespuesta === "Usuario no registrado" ||
datosRespuesta === "Contraseña incorrecta") {
$scope.respuesta = datosRespuesta;
} else {
if (datosRespuesta.estudiante){
console.log(datosRespuesta.estudiante)
var db, Perfil, row, crearTablaPerfil, guardarPerfil, consultaPerfil;
Perfil = datosRespuesta.estudiante;
db = $cordovaSQLite.openDB({ name: "unicesar.db" });
crearTablaPerfil = "CREATE TABLE IF NOT EXISTS Estudiante(Cedula integer primary key, Nombre text, Apellido text, Rol integer, Facultad text, Programa text, Semestre integer)";
guardarPerfil = "INSERT INTO Estudiante(Cedula, Nombre, Apellido, Rol, Facultad, Programa, Semestre) VALUES(?,?,?,?,?,?,?)";
consultaPerfil = "SELECT * FROM Estudiante";
$cordovaSQLite.execute(db, crearTablaPerfil);
$cordovaSQLite.execute(db, guardarPerfil, [Perfil.CeduEstu, Perfil.NombEstu, Perfil.ApelEstu, Perfil.RolEstu, Perfil.FacuEstu, Perfil.ProgEstu, Perfil.Semestre]);
$cordovaSQLite.execute(db, consultaPerfil).then(function(result){
if(result.rows.length > 0) {
row = result.rows.item(0);
alert("Datos:", row.Cedula +" "+ row.Nombre +" "+ row.Apellido +" "+ row.Rol +" "+ row.Facultad +" "+ row.Programa +" "+ row.Semestre);
$state.go('Loading');
$timeout(function() {
$state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
}, 3000);
}
} else {
console.log(response.status);
$scope.respuesta = "Error en la solicitud";
//$state.go('login');
};
});
};
};
};
I try to create the database only when the server response is successful and not when opening the application, so I do it this way.
I am using the official plugin from the ngCordova page SQLite plugin , but in the repository I see many examples and I confuses, I see that rather it is parce as if they used it almost the same that is used in a native way with javascript Repository in GitHub
Thanks in advance for any help in solving this problem.