为什么我在 ng-repeat 标签内部使用它不起作用。当我按下按钮将数据发送到服务器时,它不会推送数据,而是在我检查 mongodb 时发送 null。
如果我将输入区域移出 ng-repeat ,则不会发生这种情况
<h3 ng-repeat="review in reviews" class="icon">
<span class="glyphicon glyphicon-user " aria-hidden="true"></span>
<small >{{review.username}} </small>
<small style="float: right;">{{review.mydate}} </small>
<hr class="hr">
<div class="content">
{{review.text}}
</div>
<hr class="hr">
<div >
<a href ng-click="addLike(review)"><span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span></a>
<span class="glyphicon glyphicon-comment" aria-hidden="true"></span>
<span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span>
<a href ng-click="removeReview(review)"> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
<hr>
**<div class="newComment" ng-show='currentUser' >
<input type="text" placeholder="Pleae post your comment here..."
ng-model="newComment"
>
<button ng-value="string" type="button" class="btn btn-default"
ng-click="submitNewComment(newComment)">Comment</button>
</div>**
<ul>
<li>
{{review.comments}}
</li>
</ul>
最佳答案
您可能会遇到范围界定问题,每个 ng-repeat
创建自己的范围,但您将 ng-model
分配给单个范围项目,因此您会得到null
来自另一个项目。
尝试编写新的评论部分,例如:
<div class="newComment" ng-show='currentUser' >
<input type="text" placeholder="Please post your comment here..."
ng-model="review.newComment">
<button ng-value="string" type="button" class="btn btn-default"
ng-click="submitNewComment(review.newComment)">Comment</button>
</div>
关于javascript - ng-repeat angularjs 中的输入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59787929/