0
저는 아직 파악하기 시작한 개념 인 IIFE를 사용하는 프로젝트에서 작업하고 있습니다. 내 서비스는, 나는 그것이 정의되고 있음을 결정하기 위해 몇 가지 재스민을 사용하고 잘 될 것 같다,하지만 난 내 컨트롤러에 주입 할 때이 오류가 얻을 : 여기 컨트롤러에 서비스를 주입 할 때 알 수없는 공급자 오류가 발생합니다.
Unknown provider: StudentsServiceProvider <- StudentsService <- StudentsController
문제의 컨트롤러를 :
(function() {
'use strict';
angular
.module('ngInterview.api.students')
.service('StudentsService', StudentsService);
StudentsService.$inject = ['$http'];
function StudentsService($http) {
/**
* Exposed functions
*/
this.getName = getName; // This function serves no purpose. It's just here as an example.
this.getStudents = function() {
return $http({
url: "CUSTOM_URL_HERE",
method: "GET"
}).then(function successCallback(res) {
return res;
}, function errorCallback(res) {
return this.getStudents();
});
}
/**
* Implementations
*/
function getName() {
return 'studentsService';
}
}
})();
위에 나열된 모든 파일이 index.html을에 포함되어 있습니다 : 여기
(function() {
'use strict';
angular
.module('ngInterview.students')
.controller('StudentsController', StudentsController);
StudentsController.$inject = ['StudentsService'];
function StudentsController(StudentsService) {
/**
* Model
*/
var vm = this;
/**
* Initialization
*/
activate();
/**
* Implementations
*/
function activate() {
// Initialization code goes here
vm.students = StudentsService.getStudents();
}
}
})();
그리고
어떻게 든 거기에 엉망이 단지의 경우 서비스입니다. StudentsService에 대한 참조를 꺼내면 오류가없고 모든 파일이 올바르게 인스턴스화됩니다. 서비스StudentsService
다른
module
에 있기 때문에