Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  46] [ 5]  / answers: 1 / hits: 199064  / 11 Years ago, tue, february 11, 2014, 12:00:00

How can I clear a text input on click of a button using angularJS?



Search



The X is a seperate link, on which I would like to trigger a function.



HTML



<input type=text class=form-control data-ng-model=searchAll>
<a class=clear data-ng-click=clearSearch()>X</a>

More From » forms

 Answers
20

Just clear the scope model value on click event and it should do the trick for you.



<input type=text ng-model=searchAll />
<a class=clear ng-click=searchAll = null>
<span class=glyphicon glyphicon-remove></span>
</a>


Or if you keep your controller's $scope function and clear it from there. Make sure you've set your controller correctly.



$scope.clearSearch = function() {
$scope.searchAll = null;
}

[#72586] Monday, February 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;