1

コントローラー内でサービスを取得するのに問題があります。このプロジェクトは、私のためにテンプレートを作成し、ビルド時にファイルをマージする最新の yeoman の下にあります。

何かを変更すると、角度が機能しなくなり、コンソールにエラーは表示されません。

エラーメッセージは次のとおりです。

ReferenceError: UserService is not defined
at new <anonymous> (http://localhost:9000/scripts/controllers/people.js:5:25
at invoke (http://localhost:9000/components/angular/angular.js:2864:28)
at Object.instantiate (http://localhost:9000/components/angular/angular.js:2874:23)
at http://localhost:9000/components/angular/angular.js:4759:24
at <error: illegal access>
at Object.Scope.$broadcast (http://localhost:9000/components/angular/angular.js:8261:28)
at http://localhost:9000/components/angular/angular.js:7417:26
at wrappedCallback (http://localhost:9000/components/angular/angular.js:6797:59)
at wrappedCallback (http://localhost:9000/components/angular/angular.js:6797:59)
at http://localhost:9000/components/angular/angular.js:6834:26 

App.js :

'use strict';

angular.module('jellybeanApp', ['jellybeanApp.Service'])
.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);

$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'HomeController'
  })
  .when('/people', {
    templateUrl: 'views/people.html',
    controller: 'PeopleCtrl'
  })
  .otherwise({
    redirectTo: '/'
  });
 });

私のサービス:

'use strict';

angular.module('jellybeanApp.Service', ['ngResource'])
  .factory('UserServices', function ($rootScope, $resource, $routeParams, $location) {
return {
  users : function() {
    return $resource('notimportant',
      {action: 'user', callback: 'JSON_CALLBACK'},
      {
        get: {method: 'JSONP', params: {UserId: $routeParams.UserId}},
        query: {method: 'JSONP'},
        create: {method: 'POST'}
      });
  }
};
});

コントローラー:

'use strict';

angular.module('jellybeanApp')
 .controller('PeopleCtrl', function ($scope, UserServices) {
$scope.userResult = UserService.users().query();

});
4

2 に答える 2

2

UserServicesコントローラーに注入していますが、アクセスしようとしていますUserService。単純なタイプミスのように見えますか?

于 2013-04-10T21:00:17.177 に答える
0

余談ですが、私は

  {action: 'user', callback: 'JSON_CALLBACK'},
  {
    ...
    create: {method: 'POST'}
  });

組み込みの UserService.users.$save() のみを使用 *タイプミスのために編集

于 2013-04-10T21:34:11.737 に答える