Determine whether form input has focus

落爺英雄遲暮 提交于 2019-12-04 23:47:18
Sahu

Yes it does
you can use ngFocus and ngBlur for this purpose

here is the code

<form name="mainForm">
    <span ng-show="mainForm.email.$error.pattern && !focus">error here</span>
    <input name="email" ng-pattern="..." ng-focus="focus=true" ng-blur="focus=false" type="text" />
</form>

ngFocus and ngBlur take expression and ngShow shows upon true evaluation

You need to read about ModelOptions, debounce and updateOn can delay model change trigger event or trigger change on DOM event https://docs.angularjs.org/api/ng/directive/ngModelOptions

Check the example on the page

<div ng-controller="ExampleController">
  <form name="userForm">
    Name:
    <input type="text" name="userName"
           ng-model="user.name"
           ng-model-options="{ updateOn: 'blur' }"
           ng-keyup="cancel($event)" /><br />

    Other data:
    <input type="text" ng-model="user.data" /><br />
  </form>
  <pre>user.name = <span ng-bind="user.name"></span></pre>
</div>

Another simple option is:

 <input type="text"
        name="searchText"
        ng-model="searchText"
        ng-blur="searchIsInActive()"
        ng-click="searchIsActive()"                  
        placeholder="Search">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!