AngularJS,我怎么做UI依赖于该领域重点是什么? [英] AngularJS, how do I make the UI dependent on which field has focus?

查看:142
本文介绍了AngularJS,我怎么做UI依赖于该领域重点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AngularJS页面有几个表单输入。

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.

例如,当用户在'股票code'的投入,我想显示流行的股票codeS的列表。当他们在数量字段我想显示库存数量和交货时间。

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.

有没有包含当前输入(其中有专注的),或者我需要恢复到jQuery的聚焦状态的变量。 (现在似乎有点简陋。)

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.)

推荐答案

如何使一个指令?你可以设置每当使用者离开/进入输入的变量,并检测: http://jsfiddle.net/TZnj2/

How about make a directive? You could set a variable whenever the user leaves/enters the input, and detect that: http://jsfiddle.net/TZnj2/

请务必阅读指令指南,如果你困惑,发生了什么事: http://docs.angularjs.org/引导/指令

Be sure to read the directive guide if you're confused as to what's happening: http://docs.angularjs.org/guide/directive

另外我使用范围$适用于该指令,这里的是什么一样的解释:<一href=\"http://docs.angularjs.org/api/ng.%24rootScope.Scope#%24apply\">http://docs.angularjs.org/api/ng.$rootScope.Scope#$apply

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

这篇关于AngularJS,我怎么做UI依赖于该领域重点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆