3

I need to change the ng-model value to empty after ng-click

My code:

<div class="desc-gestures-comment ind-row">
  <textarea id="txtCommentArea" class="comment-box text-comment-listing" name="comment" placeholder="Your comment" data-ng-model="newCommentTxt">  </textarea>

  <p class="text-center"><span class="btn-common btn-blue btn-large" data-ng-click="saveParentComment(newCommentTxt)">Post Comment</span></p>
</div>

Controller function

$scope.saveParentComment = function(newCommentTxt){
  alert(newCommentTxt)
  $scope.newCommentTxt = '';
}

After the $scope.saveParentComment, I need to change the newCommentTxt value to empty.

Is it possible ?

Please suggest solution.

joeytwiddle
  • 29,306
  • 13
  • 121
  • 110
Kichu
  • 1,641
  • 4
  • 21
  • 28

3 Answers3

4

You dont have to pass the value inside a function since the scope variable is already there, just need to make the scope variable empty in your function,

 $scope.saveParentComment = function () {
        $scope.newCommentTxt = "";
    };

Here is the sample Application

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Thanks for your reply!!.I am using the same code on my end. I solved the problem.This issue is because of i am using ng-if on my end that will not pass the ng-model value. I changed ng-if to ng-show now its working fine – Kichu Dec 10 '15 at 05:00
1

If you just want to set empty string to $scope.newCommentTxt, then there is no need to do it inside a function.

You can set empty string inside html code itself.

data-ng-click="saveParentComment();newCommentTxt=''";
Kaustubh Khare
  • 3,280
  • 2
  • 32
  • 48
-3

Just make a empty scope variable like $scope.newCommentTxt = ''; the variable will be empty when the ng-click functions is called the should be like this

Post Comment

Rana Ahmer Yasin
  • 437
  • 3
  • 17