【发布时间】:2018-12-14 15:18:27
【问题描述】:
我正在尝试将 HTTP 请求放入服务文件中,以便在多个控制器中使用此功能,但出现以下错误,我尝试了多种解决方案但仍然出现此错误
这是我的 controller.js
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/LatestMovies', {
templateUrl: 'LatestMovies/LatestMovies.html',
controller: 'LatestMoviesCtrl'
});
}])
.controller('LatestMoviesCtrl',
['myServices','$scope',function(myServices,$scope) {
$scope.movies = myServices.getLatestMovies();
console.log($scope.movies ,'ggg')
}
]);
这是我的 services.js
angular.module('myApp', ['ngRoute'])
.factory('myServices', function ($http) {
return {
getLatestMovies : function () {
var service ={
movies : '',
details : []
}
var base = 'http://api.themoviedb.org/3';
var service = '/movie/popular?page=1&language=en-
US&api_key=';
var apiKey = '';
var callback = 'JSON_CALLBACK';
var url =base + service + apiKey + '&callback=' + callback;
//$scope.results = 'requesting...';
$http.jsonp(url).then(function(result, status) {
//$scope.results = JSON.stringify(data);
service.movies = result.data;
angular.forEach(result.data.results, function (value,
index) {
service.details.push(value);
});
},function(result, status) {
service.movies = 'Maybe you missed your API key?' +
JSON.stringify(result.data);
});
return service.movies;
}
}
});
错误
angular.js:14199 错误:[$injector:unpr] 未知提供者:myServicesProvider http://errors.angularjs.org/1.5.11/$injector/unpr?p0=myServicesProvider%20%3C-%20myServices%20%3C-%20LatestMoviesCtrl 在http://localhost:8000/bower_components/angular/angular.js:68:12 在http://localhost:8000/bower_components/angular/angular.js:4563:19 在 Object.getService [as get] (http://localhost:8000/bower_components/angular/angular.js:4716:32) 在http://localhost:8000/bower_components/angular/angular.js:4568:45 在 getService (http://localhost:8000/bower_components/angular/angular.js:4716:32) 在 injectionArgs (http://localhost:8000/bower_components/angular/angular.js:4741:58) 在 Object.instantiate (http://localhost:8000/bower_components/angular/angular.js:4783:18) 在 $controller
【问题讨论】:
标签: javascript angularjs node.js