AngularJS, clear input text with button

angularjs, javascript

Solution

`ng-click` is the "Angular" way to do it

just declare a function in your scope and attach it to the button's ng-click

If you wanted something more advanced, then the "Angular way" suggests creating a directive to wrap the functionality you want in it and attach it somehow to your button (depending on how you implement your directive)

If you want an example, let me know in the comments

Problem

Using `AngularJS`, what is the proper way to clear the value of a text field? I have an input field with a button next to it. The user types in it and hits the button to clear or reset it. I know I can add an `ng-click` event on the button itself and call a function, but I am not sure that is the correct way to do it. Right now all I have is: ``` <input type="text" ng-model="searchQuery" /> <button class="btn" <!--do something here maybe?-->> <i class="icon-search" ng-class="{'icon-refresh': searchQuery.length}"></i> </button> ```

Original source