[英]Accessing and refreshing AngularJS ng-repeat inside ng-repeat
我正在使用AngularJS创建一个应用程序,其中有一个通知列表,用户可以对这些通知进行评论。 但是,我不确定如何实现此评论功能。 到目前为止,我有以下内容:
HTML:
<div ng-repeat="notice in notices"> <!-- details about notice --> <div ng-repeat="comment in notice.comments"> <p>{{comment.user}} - {{comment.text}}</p> <form ng-submit="addComment()"> <input type="text" ng-model="newComment.user"> <textarea ng-model="newComment.text"></textarea> <input type="submit" value="Add comment" /> </form> </div> </div>
因此,从本质上讲,我遍历通知,然后在循环内遍历注释。 我也有一个添加新评论的表格,这对我很有用。
AddComment()
将采用新的注释值,将其添加到现有对象数组中,并通过工厂更新数据库。 但是,尽管新值确实出现在notice.comments数组中,但我不确定如何更新评论列表以显示新添加的评论。
我如何监视第二个ng-repeat中对象的状态以适应表单提交所提供的更改? 有指令吗?
您应该能够在提交时更新控制器内部的notice.comments
数组:
$scope.addComment = function() {
//update your DB, yada yada yada
//Update $scope.notices
$scope.notices[someIndex].comments.push(newComment)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.