我需要在 ng-click
之后将 ng-model
值更改为空
我的代码:
<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 函数
$scope.saveParentComment = function(newCommentTxt){
alert(newCommentTxt)
$scope.newCommentTxt = '';
}
在 $scope.saveParentComment
之后,我需要将 newCommentTxt
值更改为空。
这可能吗?
请提出解决方案。
最佳答案
你不必在函数内部传递值,因为范围变量已经存在,只需要在你的函数中将范围变量设为空,
$scope.saveParentComment = function () {
$scope.newCommentTxt = "";
};
这是样本 Application
关于angularjs - ng-click 后清除 Controller 中的 ng-model 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34193749/