2016-04-18 12 views
0

Ich habe folgende Winkelcode:

'use strict'; 
 

 
/** 
 
* @ngdoc service 
 
* @name .cordova 
 
* @description 
 
* # cordova 
 
* Factory in the APP. 
 
*/ 
 
angular.module('app') 
 
    .factory('cordova', function() { 
 
    // Service logic 
 
    // ... 
 
    
 
    var d = $q.defer(), 
 
    resolved = false; 
 

 
    var self = this; 
 
    this.ready = d.promise; 
 

 
     document.addEventListener('deviceready', function() { 
 
      resolved = true; 
 
      d.resolve($window.cordova); 
 
     }); 
 

 
    // Check to make sure we didn't miss the 
 
    // event (just in case) 
 
    setTimeout(function() { 
 
     if (!resolved) { 
 
      if ($window.cordova) d.resolve($window.cordova); 
 
     } 
 
    }, 3000); 
 

 
    // Public API here 
 
    return this; 
 

 
    /*var meaningOfLife = 42; 
 

 
    // Public API here 
 
    return { 
 
     someMethod: function() { 
 
     return meaningOfLife; 
 
     } 
 
    };*/ 
 
});

Aber ich erhalte den folgenden Fehler:

ReferenceError: $q is not defined 
 
    at Object.<anonymous> (http://localhost:9000/scripts/services/cordova.js:15:13) 
 
    at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4625:19) 
 
    at Object.enforcedReturnValue [as $get] (http://localhost:9000/bower_components/angular/angular.js:4464:37) 
 
    at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4625:19) 
 
    at http://localhost:9000/bower_components/angular/angular.js:4424:37 
 
    at getService (http://localhost:9000/bower_components/angular/angular.js:4571:39) 
 
    at injectionArgs (http://localhost:9000/bower_components/angular/angular.js:4595:58) 
 
    at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4637:18) 
 
    at $controller (http://localhost:9000/bower_components/angular/angular.js:10042:28) 
 
    at link (http://localhost:9000/bower_components/angular-route/angular-route.js:1007:26) <div ng-view="" class="ng-scope">

Und hier ist mein In dex.html:

<!doctype html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <title></title> 
 
    <meta name="description" content=""> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1" 
 
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> 
 
    <!-- build:css(.) styles/vendor.css --> 
 
    <!-- bower:css --> 
 
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 
    <!-- build:css(.tmp) styles/main.css --> 
 
    <link rel="stylesheet" href="styles/main.css"> 
 
    <!-- endbuild --> 
 
    </head> 
 
    <body ng-app="app"> 
 

 
    
 

 
    <div ng-view></div> 
 

 
    <script type="text/javascript" src="cordova.js"></script> 
 

 
    <!-- build:js(.) scripts/vendor.js --> 
 
    <!-- bower:js --> 
 
    <script src="bower_components/jquery/dist/jquery.js"></script> 
 
    <script src="bower_components/angular/angular.js"></script> 
 
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> 
 
    <script src="bower_components/angular-animate/angular-animate.js"></script> 
 
    <script src="bower_components/angular-cookies/angular-cookies.js"></script> 
 
    <script src="bower_components/angular-resource/angular-resource.js"></script> 
 
    <script src="bower_components/angular-route/angular-route.js"></script> 
 
    <script src="bower_components/angular-sanitize/angular-sanitize.js"></script> 
 
    <script src="bower_components/angular-touch/angular-touch.js"></script> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 

 
     <!-- build:js({.tmp,app}) scripts/scripts.js --> 
 
     <script src="scripts/app.js"></script> 
 
     <script src="scripts/controllers/main.js"></script> 
 
     <script src="scripts/controllers/about.js"></script> 
 
     <script src="scripts/services/cordova.js"></script> 
 
     <!-- endbuild --> 
 
</body> 
 
</html>

+1

'.factory ('cordova', function ($ q) {' –

+0

Mögliche Duplikat injizieren von [AngularJs console.log "$ q ist nicht definiert"] (http://stackoverflow.com/questions/22379733/angularjs-console-log-q-is-not-defined) – Shanimal

Antwort

6

Sie haben $q in yout Fabrik

angular.module('app').factory('cordova', function ($q) { 
    // Some code... 
}); 
+0

Vielen Dank, Irgendeine Idee auf - http : //stackoverflow.com/questions/36646564/unable-to-invoke- controller-constructor-and-submit-function? noredirect = 1 # comment60888551_36646564 – Smitha

+0

Schau dir meine Antwort an, um zu sehen, ob sie dein Problem löst;) – ddepablo

+0

Cool;) Thanks a ton! – Smitha