Friday 24 June 2016

angularjs - Clear ng-model value in controller after ng-click




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



My code:






Post Comment






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.


Answer



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


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...