javascript - Injection error with controllers and service in same module -
i'm trying create single angular module has controllers , service defined in same module. im getting , unknown provider error error: $injector:unpr. i'm not redefining module multiple times i'm not sure problem is.
// 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(); /** * turn string 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}); /** * turn string date object * @param date * @returns {date} */ $scope.todate = function(date) { return new date(date); }; }]);
the issue can find blogmodule
needs use ngroute
module, in order able inject $routeparams
so change
var blogmodule = angular.module('blogmodule', []);
to
var blogmodule = angular.module('blogmodule', ['ngroute']);
Comments
Post a Comment