我试图从控制器调用服务中的方法并收到错误:
' TypeError:undefined不是函数'。
有没有人发现我的设置有什么问题?
valid.js
angular.module('valid', [
'ui.router',
'valid.controllers',
'valid.service'
]).config(function config($stateProvider) {
$stateProvider
.state('valid', {
url: '/valid',
views: {
"main": {
controller: 'ValidCtrl',
templateUrl: 'valid/valid-template.html'
}
},
data: { pageTitle: 'Valid' }
});
});
有效-controller.js
angular.module('valid.controllers', [
'ui.router',
'ngResource',
'valid.service'
]).controller('ValidCtrl', function ($rootScope, $scope, $http, validSrvc) {
validSrvc.getUserFitnessActivities(4510789);
});
有效-service.js
angular.module('valid.service', [
'ui.router',
'ngResource'
]).service('validSrvc', ['$http', function($rootScope, $scope, $http) {
var organizationId = '5319e5f6e5a';
var accessToken = 'yxqSf7y';
this.getUserFitnessActivities = function (validUserid) {
return $http({
url: 'https://api.mydomain.com/v1/organizations/' + organizationId + '/users/' + validicUserid + '/fitness.json?access_token=' + accessToken,
method: 'GET'
});
};
}]);
答案 0 :(得分:1)
我看到了几个问题:
换句话说
[ '$rootScope', '$http', function($rootScope, $http)...