I am trying to implement pagination for my Laravel 4 + angular.js 1.0.7
application by reading this article.
My code looks,
var app = angular.module('cmsPlus', ['ngResource']);
app.service( 'Post', [ '$resource', function( $resource ) {
return $resource( 'posts/:id', { id: '@id'} );
}]);
function PostCtrl($scope, $http, Post) {
$scope.init = function () {
console.log(Post); // returns empty object
$scope.posts = Post.query(); // Post.query is not a function
// $scope.posts = Post.get(); // Post.get is not a function
}
}
Why I am getting empty object with console.log(Post);
? And why it shows Post.query is not a function
error? How can I solve it?
Edit: Communicating between two factory services
Now I have two factory services,
app.factory('Data', function(){
return {
root_path: "<?php echo Request::root(); ?>/"
};
});
app.factory( 'Post', [ '$resource', function( $resource ) {
return $resource( 'posts/:id', { id: '@id'} );
}]);
How can I access Data.root_path
in Post
factory service?