如何重置文本区域后按下按钮使用angular js


how to reset text area after pressing button using angular js?

我正在做一个项目,我必须执行像社交媒体这样的行动,我卡在一个舞台上,我必须评论,然后我必须重置可编辑的div。可编辑Div代码:

<div id="txtComment"  contenteditable="true" class="form-control txtComment" style="height: 156px;  margin-bottom: 10px;">

我的按钮调用评论函数代码:

<input  type="button"   value="POST" ng-click="comment(<?php echo $itemId ?>,<?php echo $itemDesc ?>  ,user_comment,0,0,mood)">

我的函数:

$scope.comment=function (itemid, itemdescid,user_comment,replyId,parentcomId,mood)
    {
        var feeling="";
        //console.log(mood);
        if (typeof mood !== "undefined") 
        {
            feeling=mood;
            //console.log(mood+"test");
        }
        var comm="";
        if(replyId==0)
        {
          comm=$("#txtComment").html();
        }else if(replyId == parentcomId)
        {
            comm=$("#"+parentcomId+"comment").html();
            //console.log(comm);
        } else
        {
            comm=$("#"+replyId+"comment").html();
        }
        console.log(comm);
        //console.log(feeling);
        var req = {
            method:"POST",
            data:{item_Id:itemid, item_desId:itemdescid, comment:comm,commentReplyId:replyId,parent_commentId:parentcomId,User_feeling:feeling,userId:$scope.id},
            url:"<?php echo base_url()?>index.php/ItemImportance/Comment",
            headers: {
                'Content-Type': 'application/json'
            },
        };
        $http(req).then(function (response) {
            if (response.data !=null)
            {
                if(response.data.msg !=null)
                {
                    alert(response.data.msg);
                }
                else
                {
                    //var scopeNmae="item"+"_"+itemid+"_"+itemdescid;
                    // console.log(scopeNmae);
                    //$scope[scopeNmae]=response.data;
                   //console.log(response.data);
                // window.location.reload();
                   $scope.itemcomments=response.data;
                   //eraseText();
                }
            } else
            {
            }
        }, function (response) {
            console.log(response)
        });
    }

我所要做的就是在我点击评论按钮后清空我的可编辑div !请尽快帮助我。

我写了一个很简单的例子plnkr,请大家看看。

<body ng-controller="MainCtrl">
    <textarea ng-model="comment" placeholder="comment"></textarea>
    <button ng-click="comment = ''">Clear</button>   
</body>

我的建议是:

  • 保持简单
  • 不要试图把Angular和jQuery混在一起,除非你真的需要
  • 使用合适的html元素
编辑:

内容可编辑div的示例plnkr。它是AngularJS网站的一个分支,我只是添加了clear按钮。

这对我来说很有效,这里
html代码

`<textarea  [(ngModel)] ="myInput"></textarea>
 <button (click) = "this.deleteText();">clear</button>`

角代码

myInput: string;
deleteText(){  
  this.myInput = '';   
}