【发布时间】:2014-11-22 06:50:24
【问题描述】:
我想获取数据库中所有帖子的 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),但是它被深深地埋在了某个大对象中。
如何在无序列表中显示帖子?
编辑
根据 Dan 的建议,我已将控制器更改为:
angular.module('AngularRails')
.controller('PostsController', function($scope, $http) {
$http.get('/posts.json').success(function(data) {
$scope.posts = data;
});
});
没有雪茄。
【问题讨论】:
-
能否请您回复一下?
标签: ruby-on-rails ruby json angularjs