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:

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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -