javascript - How to add class to the element using Angular's ngFocus directive (or any directive embedded in Ionic Framework) at input in a template? -
this question has answer here:
- angular.js: set css when input on focus 3 answers
i have template this:
<label class="item item-input" ng-class="{'focus':authdata.username.focus}"> <--add class here if input:focus <span class="input-label">username</span> <input type="text" name="username" ng-model="authdata.username" ng-focus="" <--check if focus required ng-minlength="5" ng-maxlength="20"> </label>
how can check if input has focus , add class label? possible without external function in controller?
<label class="item item-input" ng-class="{'focus':focus===true}"> <span class="input-label">username</span> <input type="text" name="username" ng-model="authdata.username" ng-focus="focus=true" ng-blur="focus=false" required ng-minlength="5" ng-maxlength="20"> </label>
use ngfocus , ngblur directives detect focus change on element , update value of var focus
true/false accordingly.
Comments
Post a Comment