2016-04-12 22 views
0

Android telefonumda bir iyonik uygulama test ediyorum. Bir kullanıcının oturumunu kontrol etmek için bir rootScope işlevi kullanıyorum ve bu işlev chrome hata ayıklama konsolunda bir TypeError ("TypeError: $ rootScope.checkSession bir işlev değil") gösteriyor. Çevrimiçi aramamda alabildiğim en yakın şey budur. http://www.raymondcamden.com/2014/08/16/Ionic-and-Cordovas-DeviceReady-My-Solution/ fakat sessiz kalmayı başaramadım. Güvenebilirsen sevinirim. Teşekkürler!rootScope işlevleri tanınmıyor

İşte benim kod:

forkapp.run(function($ionicPlatform, $rootScope, $firebaseAuth, $firebase, $window, $ionicLoading) { 
    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    var fb = new Firebase("https://glowing-torch-9862.firebaseio.com/"); 
    if (window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if (window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 

    $rootScope.userEmail = null; 
    $rootScope.baseUrl = 'https://glowing-torch-9862.firebaseio.com/'; 

    var authRef = new Firebase($rootScope.baseUrl); 
    $rootScope.auth = $firebaseAuth(authRef); 

    $rootScope.show = function(text) { 
     $rootScope.loading = $ionicLoading.show({ 
     content: text ? text : 'Loading..', 
     animation: 'fade-in', 
     showBackdrop: true, 
     maxWidth: 200, 
     showDelay: 0 
     }); 
    }; 

    $rootScope.hide = function() { 
     $ionicLoading.hide(); 
    }; 

    $rootScope.notify = function(text) { 
     $rootScope.show(text); 
     $window.setTimeout(function() { 
     $rootScope.hide(); 
     }, 1999); 
    }; 

    $rootScope.logout = function() { 
     $rootScope.auth.$logout(); 
     $rootScope.checkSession(); 
    }; 

    $rootScope.checkSession = function() { 
     var auth = new FirebaseSimpleLogin(authRef, function(error, user) { 
     if (error) { 
      // no action yet.. redirect to default route 
      $rootScope.userEmail = null; 
      $window.location.href = '#/auth/signin'; 
     } else if (user) { 
      // user authenticated with Firebase 
      $rootScope.userEmail = user.email; 
      $window.location.href = ('#/event'); 
     } else { 
      // user is logged out 
      $rootScope.userEmail = null; 
      $window.location.href = '#/auth/signin'; 
     } 
     }); 
    }; 
    }); //ionic platform ready 
    }) 
+0

olabilir dışında $rootScope.checkSession ve diğer $ rootScope fonksiyonları tanımlamaktır. – Daniel

cevap

0

ionicPlatform.ready olay Kodunuz yürütülür ve Cordova'nın cihaz API'leri sonra yani Cordova'nın deviceready olay patlar, yüklenen ve erişim hazır ne zaman $rootScope.checkSession fonksiyon belirlenecektir. Eğer tarayıcıda iyonik uygulamayı çalıştırıyorsanız

Genellikle ionicPlatform.readywindow.ready olay eşittir ve kod çalışacaktır. Ancak, uygulamanızı bir mobil cihazda çalıştırıyorsanız ionicPlatform.ready etkinliğinin tetiklenmesi biraz zaman alacaktır. ionicPlatform.ready'da $rootScope.checkSession işlevini tanımladığınızdan, bu işlevi yalnızca deviceready olayından sonra çağırmanız gerekir. tanımlanmış önce `logout`` kullanılır;

basit bir çözüm '$ rootScope.checkSession() için ionicPlatform.ready

İlgili konular