Good morning
I want to create a separate file for each factory that I have to declare in my project, but it is not working:
App.js file
var GestaoGastos = angular.module('GestaoGastos', ['ngMaterial', 'ngRoute', 'ngMessages', 'ngResource']);
Post-service.js file
var CargoService = function(q, http) {
var self = {}
self.salvar = function(cargo) {
var deferred = q.defer()
http.post('/services/cargo/salvar', cargo).then(function(response) {
deferred.resolve(respoonse)
}, function(response) {
deferred.reject(response)
})
return deferred.promise
}
return self
}
CargoService.$inject = ['$q', '$http']
angular.module('GestaoGastos').factory('CargoService', CargoService)
And the post-cadastro-controller.js file
var CargoCadastroController = function(
scope, http, cargoService, RetornoChamadoStatus) {
scope.cargo = {
codigo: '',
descricao: ''
}
scope.salvar = function() {
cargoService.salvar(scope.cargo).then(function(response) {
var retorno = response.data
if (retorno.status == RetornoChamadoStatus.OK) {
alert(retorno.mensagem)
} else {
alert(retorno.mensagem)
}
}, function(response) {
})
}
}
CargoCadastroController.$inject = ['$scope', '$http', 'CargoService', 'RetornoChamadoStatus']
GestaoGastos.controller('CargoCadastroController', CargoCadastroController)
But the following error appears:
Error: [$ injector: unpr] link $ injector / unpr? p0 = CargoServiceProvider% 20% 3C- % 20CargoService% 20% 3C-% 20CargoCadastroController
If we access the link we can see:
Error: $ injector: unpr Unknown Provider Unknown provider: CargoServiceProvider