douquanzhan0315 2016-06-28 09:59
浏览 76

如何在使用角度js按下按钮后重置文本区域?

I am working on a project where i have to perform actions like social media, i stuck on a stage where i have to comment and then i have to reset that editable div. Editable Div code:

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

My button for calling comment function Code:

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

my function:

$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)
        });

    }

what i have to do is just empty my editable div after i click on comment button! please help me as fast as you can.

  • 写回答

1条回答 默认 最新

  • dongyi1921 2016-06-28 10:33
    关注

    I wrote a really simple example plnkr, please have a look at it.

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

    My recommendations are:

    • Keep it simple
    • Don't try to mix Angular with jQuery, unless you really have to
    • Use appropriate html elements

    Edit:

    Example plnkr with content editable div. It's a fork from the AngularJS website, I just added the clear button.

    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?