2

Is it possible to do something like this -> Clear icon inside input text

only in angular.js? I need it for my angular application and due to various private scopes I can't get it working with jQuery.

Community
  • 1
  • 1
frog
  • 93
  • 2
  • 8
  • i have to add, that ng-show(!input=="") won't work, becouse inputs ng-model is always something(i use it as placeholder for older IE's). – frog May 23 '14 at 14:18
  • 2
    you could take a look at this answer: http://stackoverflow.com/questions/21468669/input-textbox-mimic-clear-text-x-button-just-like-select2-dropdown-component – paul May 23 '14 at 14:21
  • i don't get the 'ng-model is always something' part – nilsK May 23 '14 at 14:29
  • I think @frog means that the ngModel is never empty/null as it contains the place holder text whenever it's been emptied. – Chucky Oct 10 '14 at 07:41

3 Answers3

3

Assuming you are using ng-model:

<div class="container">
    <input type="text" ng-model="someTextField" />
    <button ng-click="someTextField = ''">x</button>
</div>
romiem
  • 8,360
  • 7
  • 29
  • 36
2

I have ported the original jquery implementation to Angular JS.

enter image description here

GitHub

A G
  • 21,087
  • 11
  • 87
  • 112
0

I've created a directive through which you can clear inputs.

Check out the clear-icon directive at GitHub

Gangadhar Jannu
  • 4,136
  • 6
  • 29
  • 49