I am currently working with a table on the frontend.
<table class="table table-hover">
<thead>
<tr>
<th> Account Entry Number </th>
<th> Date </th>
<th> Account Name </th>
<th> Description </th>
<th> Debit </th>
<th> Credit </th>
<th> </th>
</tr>
</thead>
<tbody>
<tr *ngFor="let journalEntry of journalEntries">
<td>
<input [(ngModel)]="journalEntry.id" type="text" class="form-control" placeholder="id">
</td>
<td>
<input [(ngModel)]="journalEntry.date" type="text" class="form-control" placeholder="Journal entry date">
</td>
<td>
<input [(ngModel)]="journalEntry.account.name" type="text" class="form-control" placeholder="Account name">
</td>
<td>
<input [(ngModel)]="journalEntry.description" type="text" class="form-control" placeholder="Description"></td>
<td>
<input [(ngModel)]="journalEntry.debit" type="text" class="form-control" placeholder="debit">
</td>
<td>
<input [(ngModel)]="journalEntry.credit" type="text" class="form-control" placeholder="credit"></td>
<td>
<button (click)="saveJournal(journalEntry)" class="btn btn-primary">
<i class="fa fa-save">
</i>
</button>
<button (click)="deleteJournal(journalEntry)" class="btn btn-danger">
<i class="fa fa-trash-o">
</i>
</button>
</td>
</tr>
</tbody>
</table>
and in the module I have the following:
savePosition( positionEntry: PositionEntry ) {
this.journalEntry.positionEntries.push( positionEntry );
console.log(this.journalEntry);
}
After inserting my first array named "positionEntry" into the object "journalEntry", the object will display these values:
Date: "" ID: "" Position Entries: Array(1) 0: Position Entry account: "2" debit: "2" description: "2" credit: "2" id: 0 proto: Object length: 1 proto: Array(0) user: "" _id: ""
However, when I insert a second value, the old value is overridden by the new one. Furthermore, if I make any changes to the input field, it overrides all arrays in the object "journalEntry". I'm not sure why this is happening, as I've already pushed the data to the object. Why is ngModel linked to the arrays inserted in the object?
Thank you for your assistance.