-2
私はAjax呼び出しに使用するコメントを返信して保存するコメントの 'id'を取得したいと思います。私は現在、ng-modelで他のものをつかむことができますが、jqueryを使用していた場合のように値を取得するために、非表示の入力でvalue = "{{this.id}}"の戦術を使用することはできません。 。ng-repeatの後に1つの要素 'id'を分離して取得する必要があります
<script type="text/ng-template" id="comments-temp">
<div>
<ul class="comments" ng-repeat="comment in ctrl.comments">
<li>
<div class="comment" id="{{comment.id}}">
<div class="comment-author">
<a href="#" style="background-image: url('assets/img/tmp/agent-1.jpg');"></a>
</div><!-- /.comment-author -->
<div class="comment-content">
<div class="comment-meta">
<div class="comment-meta-author">
Posted by <a href="#">admin</a>
</div><!-- /.comment-meta-author -->
<div class="comment-meta-reply">
<a href="#" ng-click="showPanel = true">Reply</a>
</div>
<div class="comment-meta-date">
<i class="fa fa-calendar"></i><span>{{comment.dateAdded | date: 'medium'}}</span>
</div>
</div><!-- /.comment -->
<div class="comment-body">
<div class="comment-item" id="commentTitle">
<h6>{{comment.title}}</h6>
</div>
{{comment.body}}
</div><!-- /.comment-body -->
</div><!-- /.comment-content -->
</div><!-- /.comment -->
<panel ng-show="showPanel">
<div class="comment-create" ng-model="ctrl.reply">
<form method="post" action="?">
<div class="row">
<div class="col-sm-4">
<div class="form-group ">
<label>Title</label>
<input type="text" class="form-control" ng-model="ctrl.reply.title">
</div><!-- /.form-group -->
</div><!-- /.col-* -->
<div class="col-sm-4">
<div class="form-group hidden">
<label>Title</label>
<input type="text" class="form-control" ng-model="ctrl.reply.name">
</div><!-- /.form-group -->
</div><!-- /.col-* -->
<div class="col-sm-4">
<div class="form-group hidden">
<label>ParentId</label>
<input type="text" class="form-control" value="{{comment.id}}" ng-model="ctrl.reply.parentId">
</div><!-- /.form-group -->
</div><!-- /.col-* -->
</div><!-- /.row -->
<div class="form-group">
<label>Message</label>
<textarea class="form-control" rows="5" ng-model="ctrl.reply.body"></textarea>
</div><!-- /.form-group -->
<div class="form-group-btn">
<button type="button" ng-click="ctrl.replyComment(ctrl.reply); showPanel = false;" class="btn btn-primary pull-right">Post Reply</button>
</div><!-- /.form-group-btn -->
</form>
</div>
</panel>
<div style="height:35px"></div>
</li>
</ul>
</div> <!--comment temp end-->
私が明らかになってきました願っています。私が欲しいのはこれです:
<script>
function _replyComment(data){
vm.commentData = data;
vm.commentData.blogId = vm.blogId;
vm.commentData.userId = page.currentUserId;
vm.commentData.typeId = 1;
vm.commentData.parentID = //??????? where I want the value the id of the comment I'm replying too
console.log(vm.commentData);
comments.services.insert(data, _onSuccessComment, _onError);// my ajax is in a separate .js file. it's not important for this demo
}
</script>
この後、私はもちろん、DOMの回答を適切に入れ子にする方法を見つけなければなりません。しかしこれは別の日の質問です。これは、Jqueryが角度よりも簡単な場所です。
ありがとうございます!
返信をクリックすると、そのコメントのIDがコントローラ変数に格納されます。 'ctrl.reply.id' – holtc
あなたはもう少し明示できますか? ng-click = "ctrl.reply(data); ctrl.reply.id = comment.id"?申し訳ありません、私は理解していません – AlexBot
ああ。わかりました。ありがとうございました!!! – AlexBot