0

I have html table and I am binding data from an array in that table. I am changing some values in the array but my changes are not getting reflected in the table. The data is not binded properly. How can I solve this issue.

Html code -

<tr *ngFor="let process of processToShow; let i = index">
<td>{{ process.processName}}</td>
<td >
  {{ process.processStatus }}
</td>
</tr>

I have an array in ts file like:

processToShow: Array[any] = [{id: 1, processName:"P1", processStatus:"Running"},
{id: 2 processName:"P2", processStatus:"Not Running"},
{id: 3, processName:"P3", processStatus:"Running"}];
..
    this.processToShow[1].processStatus="Starting.."

I want to change the value from view to source but it is not giving correct value in Html table printing the old value only.

Any ways through which I can properly bind values in HTML table from the source.

4
  • Do you use any change detection strategy? Commented Jul 15, 2022 at 5:14
  • You can refer to this: stackoverflow.com/a/57011090/11303128 Commented Jul 15, 2022 at 5:16
  • @VinceCyriac no, not yet Commented Jul 15, 2022 at 5:22
  • @ĐỗvănThắng sadly that answer did not work for me.. But you understood my problem my table values are not getting updated in view even they show as updated in console Commented Jul 15, 2022 at 5:33

2 Answers 2

0

Angular change detection won't trigger if you mutate the objects in the array

this.processToShow[1].processStatus="Starting.."

You should use an approach that updates the array in an immutable manner

Sign up to request clarification or add additional context in comments.

Comments

-1

I think there is an issue with your declaration of array variable Try updating code as follows

processToShow: Array<any> = [
  {id: 1, processName:"P1", processStatus:"Running"},
  {id: 2, processName:"P2", processStatus:"Not Running"},
  {id: 3, processName:"P3", processStatus:"Running"}
];

...

this.processToShow[1].processStatus="Starting.."

2 Comments

I wrote it wrong in que.. I am actually doing this way only.. The actual problem is my table values are not getting updated in view even they show as updated in console when I update the array elements in ts file. They are not binding properly. Thanks for your ans!
the code which I have written in que is just for understanding the problem... This is my actual code.. pastebin.mozilla.org/VFZZJVzV

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.