未知提供商:PostProvider< - Post

时间:2014-09-27 11:29:05

标签: angularjs ruby-on-rails-4

我是角色新手,在尝试从rails后端检索博客帖子列表时遇到此异常。 任何人都可以帮助我,我无法找到这个问题的确切解决方案。

Error: [$injector:unpr] Unknown provider: PostProvider <- Post
http://errors.angularjs.org/1.2.22/$injector/unpr?p0=PostProvider%20%3C-%20Post

var myApp = angular.module(&#39; Emangu&#39;,[&#39; ngRoute&#39;,&#39; ngResource&#39;]);

//Routes 

myApp.config([
  '$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
    $routeProvider.when('/blog', {
      templateUrl: '/templates/posts/index.html',
      controller: 'PostListCtr'
    });
  }
]);

//Controllers

myApp.controller("PostListCtr", ['$scope', '$http', '$resource', 'Posts', 'Post', '$location', function ($scope, $http, $resource, Posts, Post, $location) {

    alert("hello");
    $scope.posts = Posts.query();
    $scope.deletePost = function (Post) {
        if (confirm("Are you sure you want to delete this Post?")) {
            Post.delete({ id: Post }, function () {
                $scope.posts = Posts.list();
                $location.path('/');
            });
        }
    };
}]);

//resources

myApp.factory('Posts', ['$resource', function ($resource) {
  return $resource('/posts.json', {}, {
    query: { method: 'GET', isArray: true },
    create: { method: 'POST' }
  })
}]);

1 个答案:

答案 0 :(得分:1)

添加Post工厂(服务)或将其从PostListCtr依赖项中删除