编辑值时输入失去焦点.使用ngFor和ngModel.角度5 [英] input loses focus when editing value. Using ngFor and ngModel. Angular5

查看:141
本文介绍了编辑值时输入失去焦点.使用ngFor和ngModel.角度5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的列表,该列表将双向绑定到 hero.component.ts 中的参数 hero .

I have a simple list that binds two-way to a parameter hero in hero.component.ts.

尽管当我开始在输入字段中输入内容时,它会失去焦点,我必须再次单击它.我应该怎么做才能允许用户编辑输入值,而输入字段不会丢失目标?

Though when I start typing in the input field it loses focus and I have to click it again. What am I supposed to do in order to allow the user edit the input value without the input field loses target?

 <li *ngFor="let power of hero.powers; let i = index">
      <input [(ngModel)]="hero.powers[i]"/>
 </li>

推荐答案

使用angular的trackBy函数可以解决该问题.

Using trackBy function of angular fixes the issue.

显示该示例的实时示例

这篇关于编辑值时输入失去焦点.使用ngFor和ngModel.角度5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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