我想要获取数据库中所有帖子的JSON对象。
这里的模块:
angular
.module('AngularRails', [
'ngRoute',
'templates'
]).config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'HomeCtrl'
});
});
控制器:
angular.module('AngularRails')
.controller('PostsController', function($scope, $http) {
var posts = $http.get('/posts.json').success(function(data){
return data;
});
$scope.posts = posts;
});
的视图:
<h1>The Home View!</h1>
<ul>
<li ng-repeat='post in posts'>
{{ post.title }}
</li>
</ul>
当我检查控制台,我可以看到,该请求是由指定的URL(并且可以看到我想要的JSON),但是它深深地埋在一些大对象内。
如何在无序列表中显示帖子?
编辑
按照丹的建议,我已经改变了控制器这样的:
angular.module('AngularRails')
.controller('PostsController', function($scope, $http) {
$http.get('/posts.json').success(function(data) {
$scope.posts = data;
});
});
没有雪茄。
能否请您发布回应? – cthulhu 2014-11-22 13:49:52