如何在不使用输入标签的情况下停止使用 angular 中的 keyup 键入每个单词?

问题描述

当我开始在我的编辑字段中输入内容时,我每次按下一个键都会输入输入的单词。例如,当我开始输入“cat”时,我得到的是“catcat”,而不是我只想要“cat”。我怎样才能做到这一点?

我也收到以下错误

错误类型错误:无法读取未定义的属性“textContent” 来自 changeValue 函数

这是我的HTML代码

 <table class="table-hover">
                        <thead>
                          <tr class="second-heading-row">
                            <th>Medicine</th>
                            <th>Strength</th>
                        
                          </tr>
                        </thead>
                        <tr *ngFor="let medicine of medicineList; let id = index">
                          <td class="text-left">
                            <span (keyup)="changeValue(id,'medicine',$event)" (blur)="updateList(id,$event)"
                              contenteditable="true">{{medicine.medicine}}</span>
                          </td>
                          <td class="sn">
                            <span contenteditable="true" (keyup)="changeValue(id,'strength',$event)"
                              (blur)="updateList(id,$event)">{{medicine.strength}}</span>
                          </td>
                          
                        </tr>
                      </table>

这是我的 ts 文件

......

editField: string;
  medicineList: Array<any> = [
    { id: 1,medicine: '',strength:''},{ id: 2,{ id: 3,];
updateList(id: number,property: string,event: any) {
    const editField1 = event.target.textContent;
    this.medicineList[id][property] = editField1;
  }

changeValue(event: any) {
    this.editField = event.target.textContent;
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...