javascript - 为什么 ng-repeat-start 和 ng-repeat-end 无法正常工作?

标签 javascript angularjs

我正在尝试使用 Angular JS(也使用 Laravel)构建一个简单的评论应用程序,这里是一个代码:

<div ng-controller="CommentController">
    <div ng-repeat-start="comment in comments" class="comment">
        <h3>Comment {{ comment.id }} <small>by {{ comment.author }}</small></h3>
        <p>{{ comment.text }}</p>
    </div>
    <div ng-repeat-end></div>
    </div>
</div>

这是我的 JS 文件:

function CommentController($scope) {
    $scope.comments = [
        { id: 1 },
        { author: "Artem" },
        { text: "Angular comment" }
    ];
} 

这是输出:


的评论 1


Artem 的评论


评论者

Angular 评论

我正在使用 AngularJS 1.2.22,如果这可以帮助你。

最佳答案

您的 JSON 对象可能格式错误。

根据您想要实现的目标,它应该采用以下格式:

$scope.comments = [
    { id: 1, author: "Artem", text: "Angular comment" },
    { id: 2, author: "Other", text: "Other Angular comment" }
];

关于javascript - 为什么 ng-repeat-start 和 ng-repeat-end 无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25307456/

相关文章:

javascript - 替换值时 AngularJS View 不更新

javascript - 在 ng-repeat 中突出显示单个元素

javascript - 无法读取输入| Angularfire + Firebase

javascript - 路由更改时 AngularJS 调用范围函数

javascript - 定义多个布局 emberjs

javascript - Firebase Cloud Functions 在 forEach 循环中更改另一个 Node 的数据

javascript - 在 Angularjs 中操作 {} 内的字符串

android - ionic 框架同步数据和离线工作

javascript - Angular HTTP 在第一次点击时不起作用

javascript - SlickGrid 中的单元格工具提示