2013-04-10 82 views
1

我无法在控制器中获得我的服务。这个项目在 最新版本中为我创建模板并在构建时合并文件。获取资源到控制器中

当改变角度刚停止工作,并没有错误显示在控制台。

的错误信息是:

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(); 

}); 

回答

2

您正在向您的控制器注入UserServices,但随后尝试访问UserService。看起来像一个简单的错字?

+0

哇,那是没有的伎俩,谢谢你这么多。如果你看起来很长,你显然会错过这个明显的。我应该将此线程标记为答案还是只删除它? – ArniReynir 2013-04-10 21:06:35

+1

@ArniReynir我会亲自感谢接受的答案=) – jszobody 2013-04-10 21:07:21

0

在一个侧面说明,我将放弃

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

,并只使用内置UserService.users。$保存() *编辑的错字