问题描述
当我开始在我的编辑字段中输入内容时,我每次按下一个键都会输入输入的单词。例如,当我开始输入“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 (将#修改为@)