angular.js:14362 Error: [$injector:unpr] Unknown provider: reportTypeServiceProvider <- reportTypeService <- ReportTypeController
오류가 발생합니다.
나는 이것에 관해 많은 자료를 찾았지만 여전히 문제가 내 코드에 무엇인지 파악할 수 없습니다. 여기있다 :
pitchviz.js :
(function() {
'use strict';
angular
.module('pitchviz', [
'pitchviz.config',
'pitchviz.routes',
'pitchviz.report-types'
]);
angular
.module('pitchviz.config', []);
angular
.module('pitchviz.routes', ['ngRoute']);
angular
.module('pitchviz')
.run(run);
run.$inject = ['$http'];
function run($http) {
$http.defaults.xsrfHeaderName = 'X-CSRFToken';
$http.defaults.xsrfCookieName = 'csrftoken';
}
})();
pitchviz.config.js :
(function() {
'use strict';
angular
.module('pitchviz.config')
.config(config);
config.$inject = ['$locationProvider'];
function config($locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}
})();
pitchviz.routes.js :
(function() {
'use strict';
angular
.module('pitchviz.routes')
.config(config);
config.$inject = ['$routeProvider'];
function config($routeProvider) {
$routeProvider.when('/', {
controller: 'ReportTypeController',
controllerAs: 'vm',
templateUrl: '/static/templates/report-types/report-types.html'
}).otherwise('/');
}
})();
보고서 - 유형/보고서 -types.modules.js :
(function() {
'use strict';
angular
.module('pitchviz.report-types', [
'pitchviz.report-types.controllers',
'pitchviz.report-types.services'
]);
angular
.module('pitchviz.report-types.controllers', []);
angular
.module('pitchviz.report-types.services', []);
})();
보고서 - 유형/컨트롤러/보고서 - type.controller.js :
(function() {
'use strict';
angular
.module('pitchviz.report-types.controllers')
.controller('ReportTypeController', ['reportTypeService', ReportTypeController]);
ReportTypeController.$inject = ['reportTypeService'];
function ReportTypeController(reportTypeService) {
var vm = this;
vm.reportType = undefined;
activate();
function activate() {
reportTypeService.get().then(reportTypeSuccess, reportTypeError);
function accountSuccess(data, status, headers, config) {
console.log(data);
vm.reportType = data.data;
}
function reportTypeError(data, status, headers, config) {
console.log(data);
console.log(status);
}
}
}
})();
보고서 형/서비스/보고서 - type.service.js는 :
(function() {
'use strict';
angular
.module('pitchviz.report-types.services')
.service('reportTypeService', ['reportTypeService', reportTypeService]);
reportTypeService.$inject = ['$http'];
function reportTypeService($http) {
var reportTypeService = {
get: get
};
return reportTypeService;
function get() {
console.log("service");
return $http.get('/api/report-types/');
}
}
})();
여기 무슨 일이야? 감사!
가 음, 어디 .... 워, 여기 구문은 매우 혼란 스럽다.$ inject를 사용하려면 $ inject 만 사용하고 배열을 통해 주입하지 마십시오 (예 : https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md# 데이터 분리 호출). 여기에 무슨 일이 일어나고 있는지 이야기하기가 어렵습니다. reportTypeService를 reportTypeService에 삽입하려고하는 것처럼 보입니다. 이해가되지 않습니다. –
생성 한 서비스, 컨트롤러 등은 index.html 파일에 주입했습니다.이 유형의 오류는 일반적으로 각도가 삽입중인 종속성 중 하나를 찾을 수없는 경우에 발생합니다. – pritesh
'.service ('reportTypeService', [ 'reportTypeService', reportTypeService]); reportTypeService. $ inject = [ '$ http'];'좋지 않습니다. 그 중 하나에 붙이면 (그리고 btw, 인라인 주석이 잘못됨). – estus