TypeError:undefined在返回资源时不是函数

时间:2016-05-13 06:55:45

标签: javascript angularjs ionic-framework

我在问这里之前用谷歌搜索但没有运气。

我正在尝试使用ngresource调用rest服务但是app UI没有启动,因为它正在打破

angular.module('app.services', ['ngResource'])
    .factory('BlankFactory', [function(){
    }])

.factory('User', [function($resource){
    return $resource('http://1.2.3.4:1234/UASAPI/userRegistration');
    }])

.service('BlankService', [function(){
    }]);

这是我的service.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">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/ionic/js/angular-resource.min.js"></script>

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

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <style type="text/css">
      .platform-ios .manual-ios-statusbar-padding{
        padding-top:20px;
      }
      .manual-remove-top-padding{
        padding-top:0px; 
      }
      .manual-remove-top-padding .scroll{
        padding-top:0px !important;
      }
    </style>

    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/routes.js"></script>
    <script src="js/services.js"></script>
    <script src="js/directives.js"></script>

    <!-- Only required for Tab projects w/ pages in multiple tabs 
    <script src="lib/ionicuirouter/ionicUIRouter.js"></script>
    -->

  </head>
  <body ng-app="app" animation="slide-left-right-ios7">
  <div>
    <div>
        <ion-nav-bar class="bar-stable bar-balanced">
            <ion-nav-back-button class="button-icon icon ion-ios-arrow-back"></ion-nav-back-button>
        </ion-nav-bar>
        <ion-nav-view></ion-nav-view>
    </div>
</div>
  </body>
</html>

这是我的index.html

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])

.run(function($ionicPlatform) {
  $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 && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

我从http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-resource.min.js

下载了angular-resource.min.js

这是我的app.js

{{1}}

有人可以为我所缺少的东西提供帮助。

1 个答案:

答案 0 :(得分:1)

User工厂有问题,在工厂功能中使用它之前,您还没有注入$resource对象。

.factory('User', ['$resource', //<-- $resource dependency was missing here.
  function($resource){
    return $resource('http://1.2.3.4:1234/UASAPI/userRegistration');
  }
])
  

另外请确保,角文件版本&amp; ng-resource版本应该   不要错配。