想在各个地方添加评论

时间:2016-02-17 07:57:43

标签: angularjs node.js mongodb

以下是angular.js形式的线程注释的结构。

<form>
<ul class="unstyled">
    <!--  ng-class="{ '{{childcond}}': $index == selectedIndex }"  -->
    <li ng-repeat="comment in comments" class="{{childcond}}"  ng-init=" childcond=checkChild(comment.slug); reply.parentSlug=comment.slug; idstring=slashRemove(comment.slug);" >
        <strong>{{comment.author}}</strong><br>
        <p>
            {{comment.body}}
        </p>
        <a href="javascript:void(0)" class="replycomment" >reply</a>
        <div id="{{idstring}}" style="display:none;" >
            <input type="text" placeholder="Your Name" ng-model="reply.replyAuthor"><br>
            <span style="display:none;">
            <input type="text" class="hidevalue" ng-model="reply.parentSlug" ng-value="{{comment.slug}}" >
            </span>
            <textarea name="" id="" cols="30" rows="10" placeholder="Comment" ng-model="reply.replyBody"></textarea>
            <input class="btn-primary" type="submit" value="reply" ng-click="replyComment(reply,$index)">
        </div>
    </li>
</ul>

当我回复评论时,我将在最后一位收到我的评论。enter image description here

这是我在angular.js文件中的回复代码。

$scope.replyComment = function(reply,$index) {
    socket.emit('comment', { author: reply.replyAuthor, 
                             body: reply.replyBody, 
                             parent_slug:reply.parentSlug });

    clearForm();
};
socket.on('comment', function(comment) {
   $scope.$apply(function() {
       console.log(comment);
       $scope.comments.push(comment);
    });
});

console.log(comment)给出了以下结构。

enter image description here 任何帮助将不胜感激!!!

0 个答案:

没有答案