I have the following javascript and html that allows me to click a button to edit text, how do I make it so that it works with angular2 if there are multiple buttons?
<button>Button Text Could Be Editable</button><br />
<button (click)="modifyText()" data-edit="0">Edit Button Above</button>
<script>
function modifyText() {
this.previousElementSibling.previousElementSibling.contentEditable = !!(+(this.dataset.edit = this.dataset.edit == 0 ? 1 : 0))
}
</script>
In angular2, I have a list of students in my scope that I want to be rendered on a button, but I can "Edit" their name on the button only if I click on the specific button.
// this is part of the component
this.students = ['John', 'Jacob', 'Patty'];
// this is the html in my template for the component
<button *ngFor="name of students" (click) = "modifyText()">{{name}}</button><br />
How do I modify modifyText() function within the component so that in angular2, I can get a reference to the specific button and make it editable just like in my non-angular example for a single button?
Am looking for a response using the latest version of Angular as I know this has changed a couple of times.