我在调用控制器中的工厂时出现问题。工厂应该对控制器调用执行REST请求,但是发生了这个错误:
Error: [$injector:unpr] Unknown provider: SearchServiceProvider <- SearchService <- HomeController
我试图解决这个问题已有好几天了,但没有办法解决这个问题。
busca.app.js
(function () {
'use strict';
angular
.module('saldanhaTransporte', ['ngMessages'])
.factory('SearchService', Service);
function Service($http) {
var service = {};
service.SearchPendingDeliveries = SearchPendingDeliveries;
return service;
function SearchPendingDeliveries(docNumberClient, callback) {
//some code
}
}
})();
home.controller.js
(function() {
'use strict';
angular
.module('saldanhaTranporte', [])
.controller('HomeController', HomeController);
function HomeController(SearchService) {
var vm = this;
vm.searchDeliveriesFromUser = searchDeliveriesFromUser;
function searchDeliveriesFromUser() {
SearchService.SearchPendingDeliveries(vm.identifierNumber, function (result) {
if (result === true) {
console.log(true);
} else {
console.log(false);
}
});
};
};
})();
的index.html
...
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="https://code.angularjs.org/1.5.8/angular-messages.js"></script>
<script src="service/busca.app.js"></script>
<script src="home/home.controller.js"></script>
...
答案 0 :(得分:0)
您要声明两次相同的模块
尝试更改
angular
.module('saldanhaTranporte', [])
.controller('HomeController', HomeController);
要
angular
.module('saldanhaTranporte')
.controller('HomeController', HomeController);
没有module()
中的第二个参数,它是一个getter而不是一个setter并返回对现有模块的引用