绑定输入获取angularjs聚焦 [英] Bound Input gets unfocused in angularjs

查看:138
本文介绍了绑定输入获取angularjs聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行这个简单的code。与angularjs:

I am running this simple code with angularjs :

HTML:

<div ng-app ng-controller="AController">
    <code>{{ itemsInArray }}</code>
    <div ng-repeat="item in itemsInArray">
        <input ng-model="itemsInArray[$index]" />
    </div>
</div>

JavaScript的:

function AController($scope) {
    $scope.itemsInArray = ["strA", "strB", "strC"];
}

索引到数组,但进入一个字符输入失去焦点后,当绑定似乎正常工作。结果
你可以在这里找到工作code这个小提琴: http://jsfiddle.net/QygW8/

推荐答案

我认为这正在发生的事情,因为你操纵它遍历NG-重复相同的项目。所以NG-重复看到了该项目的改变并重新运行`NG重复这些再生的项目。

I think this is happening because you are manipulating the same item which is iterated over ng-repeat. So ng-repeat sees a change in the item and re-runs the `ng-repeat which regenerates the items.

如果你看看你的小提琴HTML,您可能会注意到这种影响。

If you look at your fiddle html, you may notice this effect.

要使其工作,你可以做到这一点的一种方式。

To make it work, one way you can do this

http://jsfiddle.net/cmyworld/CvLBS/

在这里你改变你的数组对象数组

where you change your array to object array

$ scope.itemsInArray = {[数据:STRA},{数据:STRB},{数据:STRC}];

,然后绑定到 item.data

这篇关于绑定输入获取angularjs聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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