ng重复嵌套json数组angularJS

ng重复嵌套json数组angularJS,angularjs,json,ng-repeat,Angularjs,Json,Ng Repeat,我试图用angular ng repeat指令在嵌套的json对象中迭代注释,但在某种程度上,它似乎无法访问它,我做错了什么 这里是json posts: [ { title: 'Free pizza at club meetings', upvotes: 15, comments: [ {commento:'comment1'},

我试图用angular ng repeat指令在嵌套的json对象中迭代注释,但在某种程度上,它似乎无法访问它,我做错了什么

这里是json

        posts: [
        {
            title: 'Free pizza at club meetings',
            upvotes: 15,
            comments: [
                {commento:'comment1'},
                {commento:'comment2'}
            ]
        },
        {
            title: 'End all club emails with Laffy Taffy jokes',
            upvotes: 9,
            comments: [],
        }
];
这里是视图

    <div class="col-lg-12 col-xs-12 comment" ng-repeat="post in posts | orderBy:'-upvotes'">
    <p>{{post.title}}</p>
    <p>
        <span class="glyphicon glyphicon-plus-sign" ng-click="upVote(post)" style="cursor:pointer;"></span> Upvotes: {{post.upvotes}}
    </p>
    <p ng-repeat comment in post.comments>
    {{comment.commento}}
    </p>
</div>

{{post.title}

UpVoces:{{post.upvoces}}

{{comment.commento}


视图中的“给我一个错误”

您的ng repeat语法错误:

<p ng-repeat comment in post.comments>

应该是

<p ng-repeat="comment in post.comments">


确定只是一个格式化错误

<p ng-repeat="comment in post.comments">


只是一个小语法错误-请检查以下代码:

var-app=angular.module(“demoApp”,[]);
应用程序控制器('myCtrl',函数($scope){
$scope.posts=[
{
标题:“俱乐部会议免费披萨”,
赞成票:15票,
评论:[
{commento:'comment1'},
{commento:'comment2'}
]
},
{
标题:“用Laffy Taffy笑话结束所有俱乐部电子邮件”,
投票数:9,
评论:[{commento:'comment3'},
{commento:'comment4'}]
}
];
$scope.upVote=函数(post){}
});

{{post.title}

Upvotes:{{post.Upvotes}

{{comment.commento}


观察结果:

  • 使用

    而不是

  • $scope.posts
    对象未正确声明。使用
    $scope.posts=[]
    而不是
    $scope.posts:[]
演示

var myApp=angular.module('myApp',[]);
myApp.controller('MyCtrl',函数($scope){
$scope.posts=[
{
标题:“俱乐部会议免费披萨”,
赞成票:15票,
评论:[
{commento:'comment1'},
{commento:'comment2'}
]
},
{
标题:“用Laffy Taffy笑话结束所有俱乐部电子邮件”,
投票数:9,
评论:[],
}
];
});

{{post.title}

UpVoces:{{post.upvoces}}

{{comment.commento}


ng repeat=“comment in post.comments”
Sorry@Azola在发布我的答案之前,我没有看到你的评论。如果你发布一个答案,我会删除我的答案,这样你就可以得到代表。没什么好担心的@Bernhardhofmann请在为你解决问题的答案上打勾(勾号),这样问题就不会一直“未回答”。未回答的问题有时会让人们在可以帮助别人的时候花时间看(已经回答的)问题。