admin管理员组文章数量:1290225
I have an AngularJS page with several form inputs.
When the some of the inputs have focus, I want to change other, arbitrary, aspects of the page.
For example, when the user is in the 'stock code' input, I want to display the list of popular stock codes. When they are in the 'qty' field I want to show in-stock quantities and lead times.
Is there a variable which contains the 'current' input (the one which has focus), or do I need to revert to jQuery's onFocus. (It seems a little primitive now.)
I have an AngularJS page with several form inputs.
When the some of the inputs have focus, I want to change other, arbitrary, aspects of the page.
For example, when the user is in the 'stock code' input, I want to display the list of popular stock codes. When they are in the 'qty' field I want to show in-stock quantities and lead times.
Is there a variable which contains the 'current' input (the one which has focus), or do I need to revert to jQuery's onFocus. (It seems a little primitive now.)
Share Improve this question asked Jun 21, 2012 at 21:09 fadedbeefadedbee 44.8k48 gold badges199 silver badges349 bronze badges2 Answers
Reset to default 10How about make a directive? You could set a variable whenever the user leaves/enters the input, and detect that: http://jsfiddle.net/TZnj2/
Be sure to read the directive guide if you're confused as to what's happening: http://docs.angularjs.org/guide/directive
Also I use scope.$apply in that directive, here's an explanation of what that does: http://docs.angularjs.org/api/ng.$rootScope.Scope#$apply
ngFocus and ngBlur are built-in directives:
<input ng-focus="hasFocus = true" ng-blur="hasFocus = false" type="text">
<p ng-show="hasFocus">The field has focus!!</p>
Try demo on jsfiddle
本文标签: javascriptAngularJShow do I make the UI dependent on which field has focusStack Overflow
版权声明:本文标题:javascript - AngularJS, how do I make the UI dependent on which field has focus? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739488637a2165478.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论