I am trying to create a component that shows data in rows from a TableData model,
export class TableData{ constructor( public id: number, public country: string, public capital: string){ } }
I have my data in this component,
tableData: TableData[] = [ new TableData(1, 'Canada','Ottawa'), new TableData(2, 'USA','Washington DC'), new TableData(3, 'Australia','Canberra'), new TableData(4, 'UK','London') ];
Then in my component, I create a table like this,
<table> <tbody> <tr *ngFor="#row of tableData> <td contenteditable='true'>{{ row.id }}</td> <td contenteditable='true' (click)="onRowClick($event)">{{ row.country }}</td> <td contenteditable='true'>{{ row.capital }}</td> </tr> </tbody> <span>{{ tableData | json }}</span> </table> onRowClick(event){ console.log(event); }
I can edit the data since I marked the <td> element as "contenteditable", but I donβt know how to save it or get updated values. I checked the "event" data passed to the onRowClick method, but could not get the "id" of the string (it is empty. Event.srcElement.id or event.target.id are both empty).
In short, I want to edit the table and see how it updates the tableData variable. Sorry for not asking him for the first time.
Any guidance on solving my problem is welcome!