내 데이터베이스의 모든 게시물에 대한 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;
});
보기 : I 콘솔 검사시
<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