I have a list of objects which I am displaying using a *ngFor
on the HTML page. Now the user interacts with UI and changes one of the primitive values(boolean, from false to true).
As per my understanding the *ngFor
will only render the changes if the list object is modified completely i.e. removed and added again to the list. If I am right on this concept, then can you please suggest a method to reflect the change in the primitive type without re-initializing the component or modifying the object reference.
For Example:
<div *ngFor="let item of list">
<md-checkbox [(ngModel)]="item.selected"></md-checkbox>
</div>
User clicks on the checkbox, but the checkbox has to be ticked after certain validations from server. So let's say the checkbox needs to be unchecked and user gets a message on snack bar. So I loop through the list and modify item.selected
to false. But, the change is not reflected as i modified the primitive type selected(boolean) in the object item. So how to render the new value without reloading or initializing the page again.
Please let me know if more input is required.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…