I'm encountering an issue that keeps popping up:
Error: [$injector:unpr] Unknown provider: UsersServiceProvider <- UsersService
I attempted to address this problem by adding ['UsersService' before my controller function, after reading about it on https://docs.angularjs.org/error/$injector/unpr. However, the solution didn't seem to resolve the error.
Here is the code snippet where I have only executed yo angular
and then yo angular:service users
.
This segment belongs to controllers/main.js
angular.module('pmsFrontApp')
.controller('MainCtrl', ['UsersService',function ($scope, UsersService) {
$scope.form = { firstName: '', lastName: '' };
UsersService.fetchAll().then(function(data) {
//console.log(data);
//$scope.lista = data;
});
}]);
Similarly, this portion can be found in services/users.js
angular.module('pmsFrontApp')
.service('UsersService', function ($q,$http) {
this.fetchAll = function() {
var defer = $q.defer();
$http.get('http://localhost:8888/users', /*{
params: {}
}*/).success(function(data) {
defer.resolve(data);
}).error(function() {
defer.reject('No vieja');
});
return defer.promise;
}
});
});