I am working on a scenario where I have created a table component which can be plugged into any html template. We can pass different data to it and show.
// table component
<tbody *ngIf="tableData">
<tr class="row">
<td>{{ 'LABEL.DAY' | translate }}</td>
<td *ngFor="let data of tableData.timesheetInputs.timesheetDays | dayfilterpipe:'DAY' ">
<input [ngModel] ="data.amount" #day="ngModel" (keypress)="_keyPress($event)" (ngModelChange)="data.amount=$event" (ngModelChange)="timesheetHourChanged(data.amount,'DAY')" [disabled]="inputViewState && !isEditable" [ngClass]="{'is-invalidTimeEntry': (data.amount === '') || ((data.amount)%(0.25) != 0) || (data.amount > 24) }" />
</td>
<td>{{totalDayHour}}</td>
</tr>
<tr class="row">
<td>{{ 'LABEL.NIGHT' | translate }}</td>
<td *ngFor="let data of tableData.timesheetInputs.timesheetDays | dayfilterpipe:'NIGHT' ">
<input [(ngModel)] ="data.amount" #day1="ngModel" (ngModelChange)="timesheetHourChanged(data.amount, 'NIGHT')" [disabled]="inputViewState && !isEditable" [ngClass]="{'is-invalidTimeEntry': (data.amount === '') || ((data.amount)%(0.25) != 0) || (data.amount > 8) }" />
</td>
<td>{{totalNightHour}}</td>
</tr>
</tbody>
And in a parent component it can be invoked like this :
//first component
<timesheet-table [tableData]="weekData" #timesheetTable [inputViewState]="statusVisibility"></timesheet-table>
//second component
<timesheet-table [tableData]="editableWeekData" #timesheetTable [inputViewState]="statusVisibility" [isEditable]="editable"></timesheet-table>
The issue I am facing is the lower table
<timesheet-table [tableData]="editableWeekData" #timesheetTable [inputViewState]="statusVisibility" [isEditable]="editable"></timesheet-table>
it can be edited and by changing any cell should not affect the first timesheet-table component which is disabled. But somehow it is happening, whenever I change any field it changes in both the tables.
It seems some issue in using ngModel correctly. I might have missed something.
What can be the best possible way to avoid this issue. I don't want to create another component. I want to reuse the existing table component.