AngularJS input自动聚焦
当我们在使用ionic进行开发的时候,使用angularjs中的ng-focus指令并没有效果。
比如当我们在需要点击某个按钮然后弹出输入框,并且需要自动聚焦到这个输入框的时候。如果使用angularjs的ng-focus指令,这样是没有任何效果的。
这时候就需要我们重写focus服务。
然后给输入框设置id
<input id="inputFocus" ng-model="" type="text" placeholder="" />
最后在input对应的controller中注入focus
通过focus("inputFocus")对input进行自动聚焦。
比如当我们在需要点击某个按钮然后弹出输入框,并且需要自动聚焦到这个输入框的时候。如果使用angularjs的ng-focus指令,这样是没有任何效果的。
这时候就需要我们重写focus服务。
<pre style="background-color: rgb(255, 255, 255); font-family: 宋体; font-size: 12pt;"><pre name="code" class="html"> .factory("focus", function ($timeout, $window) { return function (id) { $timeout(function () { var element = $window.document.getElementById(id); if (element) element.focus(); }); }; })
然后给输入框设置id
<input id="inputFocus" ng-model="" type="text" placeholder="" />
最后在input对应的controller中注入focus
通过focus("inputFocus")对input进行自动聚焦。
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。