I'd like to get a JSON object of all the posts in my database.
Here's the module:
angular .module('AngularRails', [ 'ngRoute', 'templates' ]).config(function($routeProvider) { $routeProvider .when('/', { templateUrl: 'home.html', controller: 'HomeCtrl' }); }); A controller:
angular.module('AngularRails') .controller('PostsController', function($scope, $http) { var posts = $http.get('/posts.json').success(function(data){ return data; }); $scope.posts = posts; }); The view:
<h1>The Home View!</h1> <ul> <li ng-repeat='post in posts'> {{ post.title }} </li> </ul> When I check the console, I can see that the request is made to the specified URL (and can see the JSON I want), but it's buried deeply within some large object.
How can I display the posts in an unordered list?
Edit
As per Dan's suggestion, I've changed the controller to this:
angular.module('AngularRails') .controller('PostsController', function($scope, $http) { $http.get('/posts.json').success(function(data) { $scope.posts = data; }); }); No cigar.