Angularjs 未知提供程序:后提供程序<;-邮递
我不熟悉angular,在尝试从rails后端检索博客文章列表时遇到了这个异常。 谁能帮帮我吗?我找不到这个问题的确切解决办法Angularjs 未知提供程序:后提供程序<;-邮递,angularjs,ruby-on-rails-4,Angularjs,Ruby On Rails 4,我不熟悉angular,在尝试从rails后端检索博客文章列表时遇到了这个异常。 谁能帮帮我吗?我找不到这个问题的确切解决办法 Error: [$injector:unpr] Unknown provider: PostProvider <- Post http://errors.angularjs.org/1.2.22/$injector/unpr?p0=PostProvider%20%3C-%20Post 添加Post factory(服务)或将其从PostListCtr依赖项中删除
Error: [$injector:unpr] Unknown provider: PostProvider <- Post
http://errors.angularjs.org/1.2.22/$injector/unpr?p0=PostProvider%20%3C-%20Post
添加Post factory(服务)或将其从PostListCtr依赖项中删除,您的
Post
提供商在哪里?
//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' }
})
}]);