2014-11-10 2 views
0

모바일 앱을 만들기 위해 이오니아 및 각도를 사용하고 있습니다. 그러나 나는 다음과 같은 오류를 내가 응용 프로그램에서 각 캐시를 통합 할 때마다 점점 해요 :전화 갭 앱에서 앵귤러 캐시가 작동하지 않습니다.

enter image description here

가 여기 내 index.html 파일이 보이는 무엇을 같은 : 내가 설정 내 app.js 파일에 다음

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 


    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="lib/angular-cache/dist/angular-cache.min.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="cordova.js"></script> 

    <!-- your app's js --> 
    <script src="js/app.js"></script> 

    <script src="js/controllers/home-starter.js"></script> 

    <script src="js/controllers/home/loginController.js"></script> 
    <script src="js/controllers/home/signupController.js"></script> 


    <script src="js/services/services-starter.js"></script> 
    <script src="js/services/userService.js"></script> 

    </head> 
    <body ng-app="starter" animation="slide-left-right-ios7"> 

    <ion-nav-view></ion-nav-view> 
    </body> 
</html> 

하나로서 각 데이터 내 종속성 :

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'angular-data.DSCacheFactory']) 

.run(function($ionicPlatform, DSCacheFactory) { 
    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 

    DSCacheFactory('UserCache', { 
     storageMode: 'localStorage', 
     deleteOnExpire: 'aggressive' 
    }); 


    }); 

}) 

.config(function($stateProvider, $urlRouterProvider) { 


    // Ionic uses AngularUI Router which uses the concept of states 
    // Learn more here: https://github.com/angular-ui/ui-router 
    // Set up the various states which the app can be in. 
    // Each state's controller can be found in controllers.js 
    $stateProvider 


    .state('login', { 
     url: '/login', 
     templateUrl: 'templates/login.html', 
     controller: 'LoginController' 
    }) 


    $urlRouterProvider.otherwise('/login'); 

}); 

내,843에 로그인하기위한 논리를 넣었습니다파일 :

(function(){ 

    angular.module('starter.services') 
    .service('UserService', ['$http', '$q', '$ionicLoading', 'DSCacheFactory', UserService]); 

    function UserService($http, $q, $ionicLoading, DSCacheFactory){ 

     var base_url = 'http://somewhere.com'; 

     self.UserCache = DSCacheFactory.get('UserCache'); 

     self.UserCache.setOptions({ 
      onExpire: function(key, value){ 
       login.then(function(){ 
       }, function(){ 
        self.UserCache.put(key, value); 
       }); 
      } 
     }); 


     function login(user){ 

      var deferred = $q.defer(); 
      var cache_key = 'user'; 

      $ionicLoading.show(); 

      $http.post(base_url + '/api/login', user) 
       .success(function(data){ 

        $ionicLoading.hide(); 
        self.UserCache.put(cache_key, data.user); 
        deferred.resolve(data); 

       }) 
       .error(function(data){ 
        deferred.reject(); 
       }); 


      return deferred.promise; 
     }; 

     return({ 
      login: login 
     }); 

    }; 


})(); 

그리고 도움이된다면, 여기 내 config.xml 파일이다 : 나는 그냥 브라우저에서 실행할 때

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<widget id="com.ionicframework.vestor507394" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>tester</name> 
    <description> 
     An Ionic Framework and Cordova project. 
    </description> 
    <author email="[email protected]" href="http://ionicframework.com/"> 
     Ionic Framework Team 
    </author> 
    <content src="index.html"/> 
    <access origin="*"/> 
    <preference name="webviewbounce" value="false"/> 
    <preference name="UIWebViewBounce" value="false"/> 
    <preference name="DisallowOverscroll" value="true"/> 
    <preference name="BackupWebStorage" value="none"/> 
    <feature name="StatusBar"> 
    <param name="ios-package" value="CDVStatusBar" onload="true"/> 
    </feature> 
</widget> 

잘 작동하는 것 같다. 그러나 Phonegap에 업로드하여 Genymotion에 앱을 설치하고 설치하면 바로 이러한 오류가 발생합니다. 코드에서 각도 캐시를 사용하지 않으면 잘 작동합니다.

어떤 아이디어가 잘못 될 수 있습니까? 이 플러그인을 설치하거나 config.xml 파일을 편집해야합니까? 미리 감사드립니다

답변

0

제 (함수() {선언에서 서비스 선언을 제거하십시오 :

angular.module('starter.services') 
.service('UserService', ['$http', '$q', '$ionicLoading', 'DSCacheFactory', UserService]); 

function UserService($http, $q, $ionicLoading, DSCacheFactory){ ................. 

희망이 도움이!

.