Ionic中的$ resource未定义?

时间:2015-04-14 13:59:33

标签: angularjs ionic-framework ngresource ngcordova

想知道是否有人遇到过这个..我有一个项目,它使用了Ionic,ngCordova和ngResource。我用我认为正确的顺序导入它们;

    

<!-- Angular Modules -->
<script src="lib/ng-biscuit/dist/ng-biscuit.min.js"></script>
<script src="lib/angular-resource/angular-resource.min.js"></script>

<!-- ngCordova -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>

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

我的工厂很简单;

(function() {
    'use strict';
    angular.module('test')
        .factory('TestService', TestService);

    TestService.$inject = ['$resource'];

    function TestService($resource) {
        console.log('creating TestService ' + JSON.stringify($resource));
    }
})();

在浏览器上,我得到一个对象的预期日志,但是当我在模拟器中运行它时,我得到:

creating TestService undefined

以前有人遇到过这个吗?

2 个答案:

答案 0 :(得分:0)

    'use strict';

	app.factory('testService', [
		'$dependencyInjection',
		function($dependencyInjection) {
          
          var factory = {};
          
          ...
          
          return factory;
          }]);

答案 1 :(得分:0)

'use strict';

app.factory('testService', [
    '$dependencyInjection',
    function($dependencyInjection) {

      var factory = {};

      ...

      return factory;
      }]);

这对你有用吗?