In my Angular application, there is a field called maan
in the database. The value of this field is displayed twice on the frontend - one static and the other dynamic.
To store the dynamic value, I am using Angular Local Storage in the saveChanges
function. A new variable is created to hold this value:
var change_single_object = JSON.parse(localStorage.getItem('LikeWhen') || '{}') as LikeWhen
change_single_object.maan= maan; -------> This line tries to access the dynamic value (#term reference in html)
However, the above statement always refers to the static value. How can I resolve this issue?
Interface:
export interface LikeWhen {
maan: string;
}
component.ts:
export class RufusComponent {
@ViewChild('term') editElem!: ElementRef<HTMLTableDataCellElement>;
saveChanges(rec: LikeWhen, new_value: HTMLTableDataCellElement) {
localStorage.setItem('LikeWhen', JSON.stringify(rec));
var change_single_object = JSON.parse(localStorage.getItem('LikeWhen') || '{}') as LikeWhen
change_single_object.maan= maan;-------------> PROBLEM (Refers to static value)
localStorage.setItem('LikeWhen', JSON.stringify(change_single_object));
}
}
.html:
// --------static value
<mat-list-item>Static Value Amazon</mat-list-item>
<mat-list>{{latestData.maan}}</mat-list>
<mat-divider></mat-divider>
// -------dynamic value
<mat-list-item>Dynamic Value</mat-list-item>
<mat-list class="textFields">
<table>
<tr>
<td [innerHTML]='latestData.replaceHTML' #term></td>
</tr>
</table>
</mat-list>
//button
<button mat-raised-button type='button' [disabled]='confirmDisabled' (click)='saveChanges(latestData, term)'>Confirm