I have data that is displayed in a modal. However, when my data is updated and parent detects this, my modal data is never updated. Am I missing something?
PARENT:
@Input() players: Players[] = [];
showPlayers() {
const modalRef = this.modalService.open(PlayersModalComponent, {
data: { players: this.players }
},
});
}
ngOnChanges(changes: SimpleChanges) {
console.log('changes', changes);
// This shows that players has changed and gone from say 2 players to 3 players after a few actions. But modal doesn't update.
}
Modal
this.players = this.modalRef.data.players;
Modal HTML
Here I just list the players and initially they are perfect. But they do not update when a new player is added and ngChanges in parent ALSO shows there is a new row.
<modal class="modal" *ngIf="players">
<div>
<div *ngFor="let player of players">
{{player.name}}
</div>
</div>
</modal>
However, if new result is added --- since I am pulsing on API from parent. The change is detected but the list of players in modals is not updated.