I'm in the process of creating an angular module that contains controllers and a service all within the same module. The issue I'm facing is an unknown provider error Error: $injector:unpr. I have made sure not to redefine the module multiple times, so I am unsure of what the problem could be.
// index.js
var pdizzApp = angular.module('pdizzApp', [
'ngRoute',
'blogModule'
]);
pdizzApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/blog', {
templateUrl: 'app/blog/view/blog-list.html',
controller: 'BlogListController'
})
.when('/blog/:postId', {
templateUrl: 'app/blog/view/blog-detail.html',
controller: 'BlogDetailController'
})
.otherwise({
redirectTo: '/blog'
})
}]);
//blogModule.js
var blogModule = angular.module('blogModule', []);
blogModule.factory('PostService', ['$resource',
function ($resource) {
return $resource('api/blog/post/:postId', {}, {
query: {method: 'GET', params: {postId: 'posts'}, isArray: true}
});
}]);
blogModule.controller('BlogListController', ['$scope', 'PostService',
function ($scope, PostService) {
$scope.posts = PostService.query();
/**
* Convert a string into a Date object
* @param date
* @returns {Date}
*/
$scope.toDate = function(date) {
return new Date(date);
};
}]);
blogModule.controller('BlogDetailController', ['$scope', '$routeParams', 'PostService',
function ($scope, $routeParams, PostService) {
$scope.post = PostService.get({postId: $routeParams.postId});
/**
* Convert a string into a Date object
* @param date
* @returns {Date}
*/
$scope.toDate = function(date) {
return new Date(date);
};
}]);