2016-04-07 20 views
0

sqlite veritabanına bağlı olarak bir görünüm açmaya çalışıyorum. Kodum iyidir, çünkü "Sesion_activa" veri tabanına girdiğinde, istediğim bir görünümü gösterir. Ancak benim sorunum, uygulamanızı açtığım zaman önce giriş görünümünü gösterir ve 1 veya 2 saniye sonra ilgili görünüme gider.Sqlite iyonik çerçeve Etkin oturum

Sorunu nasıl çözebilirim? kullanıcı giriş edildiğinde ben varsayılan

onun html görünümü koymak istiyorum Bu benim kodudur:

App.js

var db = null;//paso 1 BD 

angular.module ('marş', [ 'iyonik', 'ngCordova', 'starter.controllers'])

.run(function($ionicPlatform, $cordovaSQLite,$state) {//paso 2 agrego cordovaSqlite 
    $ionicPlatform.ready(function() { 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 

     // Don't remove this line unless you know what you are doing. It stops the viewport 
     // from snapping when text inputs are focused. Ionic handles this internally for 
     // a much nicer keyboard experience. 
     cordova.plugins.Keyboard.disableScroll(true); 
     //creo la tabla tutoria 
     db = $cordovaSQLite.openDB({ name: 'tuto.db' });//paso 3 creo la BD 
     $cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS tutoria (id integer primary key, estado text, rolUs text, pNombre text, Inicial text, sNombre text, pApellido text, sApellido text, cedula text)"); 
     //fin creo la tabla tutoria 
     //comprobar sesion 
     var query = "SELECT * FROM tutoria"; 
     $cordovaSQLite.execute(db,query).then(function(result) { 
     for (j=0; j < result.rows.length; j++) { 
      if(result.rows.item(j).estado=="Sesion_Activa" && result.rows.item(j).rolUs=="docente"){ 
      $state.go('tabs.perfilDocente');//HERE GOES TO THE VIEW 
      }else{ 
      if(result.rows.item(j).estado=="Sesion_Activa" && result.rows.item(j).rolUs=="estudiante"){ 
       $state.go('tabsEst.perfilEstudiante');//HERE GOES TO THE 2cond VIEW 
      } 
      }    
     } 
     }); 
     //fin comprobar sesion 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 
//VISTAS 
.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 
    //Login de la APP 
    .state('login',{ 
     cache: false, 
     url:'/login', 
     templateUrl:'templates/login.html', 
     controller: 'LoginCtrl' 
    }) 
    // PADRE DE VISTAS TABS DOCENTE 
    .state('tabs',{ 
     cache: false, 
     url:'/Gtuto', 
     abstract:true, 
     templateUrl:'templates/tabs.html' 
    }) 
    //Hijos de TABS 
    .state('tabs.perfilDocente', { 
     cache: false, 
     url:'/perfil', 
     views:{ 
     'perfil-tab':{ 
      templateUrl:'templates/perfilDocente.html', 
      controller:'SalirCtrl' 
     } 
     } 
    }) 
    .state('tabs.CompDocente', { 
     cache: false, 
     url:'/componentes', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/CompDocente.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    })  
    .state('tabs.ListaTutoDocente', { 
     cache: false, 
     url:'/componentes/:nom_coe', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/ListaTutoDocente.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    }) 
    .state('tabs.CrearTutoria', { 
     cache: false, 
     url:'/componentes/:nom_coe/:paralelo', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/CrearTutoria.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    }) 
    .state('tabs.ContEdicionTuto', { 
     cache: false, 
     url:'/componentes/:Nom_coe/EdicionTutorias/:id', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/ContEdicionTuto.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    }) 
    .state('tabs.comentarios', { 
     cache: false, 
     url:'/componentes/:componentesId/:c/:f/:d', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/comentarios.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    }) 
    .state('tabs.participantes', { 
     cache: false, 
     url:'/componentes/:componentesId/:c/:f/:d/:e', 
     views:{ 
     'componentes-tab':{ 
      templateUrl:'templates/participantes.html', 
      controller:'DocenteCtrl' 
     } 
     } 
    }) 
    .state('tabs.notDoc', { 
     cache: false, 
     url:'/notificaciones', 
     views:{ 
     'notificaciones-tab':{ 
      templateUrl:'templates/NotDoc.html' 
     } 
     } 
    }) 
    // PADRE DE VISTAS TABSEST ESTUDIANTE 
    .state('tabsEst',{ 
     cache: false, 
     url:'/Gtuto', 
     abstract:true, 
     templateUrl:'templates/tabsEst.html' 
    }) 
    //Hijos de TABSEST 
    .state('tabsEst.perfilEstudiante', { 
     cache: false, 
     url:'/perfilEst', 
     views:{ 
     'perfil-tabsEst':{ 
      templateUrl:'templates/perfilEstudiante.html', 
      controller:'SalirCtrl' 
     } 
     } 
    }) 
    .state('tabsEst.CompEstudiante', { 
     cache: false, 
     url:'/componentesEst', 
     views:{ 
     'componentes-tabsEst':{ 
      templateUrl:'templates/CompEstudiante.html', 
      controller:'AlumnoCtrl' 
     } 
     } 
    })  
    .state('tabsEst.ListaTutoEstudiante', { 
     cache: false, 
     url:'/componentesEst/:nombre', 
     views:{ 
     'componentes-tabsEst':{ 
      templateUrl:'templates/ListaTutoEstudiante.html', 
      controller:'AlumnoCtrl' 
     } 
     } 
    }) 
    .state('tabsEst.notificaciones', { 
     cache: false, 
     url:'/notificacionesEst', 
     views:{ 
     'notificaciones-tabsEst':{ 
      templateUrl:'templates/NotEst.html' 
     } 
     } 
    }) 
    $urlRouterProvider.otherwise('/login'); 
}) 

cevap

0

angular.run yöntem yarış durumu ne denir sonuçlanan hangi eşzamansızdır.

ben senin $cordova.execute çok uzun sürüyor ve bu zamana kadar başvurunuzun zaten /login olarak listeledik varsayılan görünüme navigasyon ettiğini söyleyebilirim tahmin etmek olsaydı. angular.run hala navigasyondan sonra bile işliyor olduğundan, tamamlandığında sizi yönlendirecektir. Bu yüzden 2 saniyelik gecikmeyi görüyorsunuz.

Buna bir çözüm, angular.run yönteminizde herhangi bir sorgu veya gezinme mantığı yürütmemek olabilir. Bunun yerine, uygulama başlatma için bir denetleyici oluşturun. Bu kontrol cihazının ilk ekran olmasına izin verin ve bir yükleme göstergesi açın. Başlatma mantığınız bittiğinde, gitmeniz gereken yere gidin.

En iyi,