How to change html of div in angularjs? -
i have page displays comments (using ng-repeat). each comments edit button. here client's requirement.
- on clicking on edit, comment div should swapped form.
- on submitting form, form should swapped comment div.
- at time, 1 comment can updated.
so per angularjs knowledge, can single form comments. i'm getting confuse how should do? ng-swap, template directive or else. , have basic knowledge of angularjs, if can me demo/example, appreciated.
edit:
html
<div id="comment_{{$index}}" ng-repeat="comment in blog.comments track $index"> <div class="replace-with" ng-if="hidecomment != $index"> <h2> <b>comment</b> added <b>{{comment.user.fullname}}</b>, <span><span>{{comment.datetime}}</span></span> <div> <a href="javascript:void(0)" ng-click="openeditform($index, comment.unique_id)"><i class="fa fa-pencil"></i></a> <a href="javascript:void(0)"><i class="fa fa-trash-o"></i></a> </div> </h2> <p>{{comment.content}}</p> </div> </div>
js
$scope.hidecomment = null; $scope.openeditform = function (div_id, id) { $scope.hidecomment = div_id; var html = '<form role="form" name="formupdatecomment" id="formupdatecomment">' + '<div class="box-body">' + '<div class="form-group">' + '<textarea ckeditor="editoroptions" id="tacontent" name="tacontent" rows="10" cols="80" ng-model="blog.blog_comments[' + div_id + '].content" ng-change="updatecontent(' + div_id + ', \'edit\')"></textarea>' + '</div>' + '</div>' + '<div class="box-footer">' + '<div style="text-align: right;">' + '<button type="button" class="btn btn-primary" ng-click="closeeditform(' + div_id + ')">close</button>' + '</div>' + '</div>' + '</form>'; $('#comment_' + div_id).append($compile(html)($scope)); } $scope.closeeditform = function (div_id) { $('#comment_' + div_id + ' form').remove(); $scope.hidecomment = null; }
in openeditform()
, want change/swap content of div having id comment_* form. on clicking ok
button, form replaced div content (i.e, <h2>
,<p>
etc.). haven't problem load updated data etc. pain how change html content. can't go way. because headache add more inputs in form. want use angular directive.
try ng-if
.
first, in controller, define following variable responsible showing ckeditor
:
$scope.showckeditor = false;
then, in edit function, set true:
function edit(){ ... $scope.showckeditor = true; }
then, in html, this:
<ckeditor ng-if="showckeditor"> // assumption did not show own code </ckeditor> <commend-div ng-if="!showckeditor"> </comment-div>
and same buttons
hope helps
Comments
Post a Comment