I have the following code:
Template:
<button *ngFor="name of students"
(click)="modifyText($event.currentTarget)">{{name}}</button>
TypeScript
this.students = ["Carl", "Rob", "Joy];
public modifyText(htmlElement: HTMLElement) {
this.dataset.edit = !this.dataset.edit;
htmlElement.contentEditable = this.dataset.edit;
htmlElement.focus();
}
The problem is that as soon as I change the content with content editing, I seem to lose the binding to {{name}}, as if I have a separate button on the page:
<button (click)="students[0] = 'Amy'">Manual Set Name</button>
The students array changes, but when I look at the button text, this is what I โeditedโ in contenteditable and donโt show Amy at all.
source
share