In a scenario where data is being sent from two different components - let's call them OneComponent
and
TwoComponent. These components send their data to a <code>ResultComponent
through the Input()
decorator. Within the ResultComponent
, the received data is merged using the OnChanges
interface:
ngOnChanges(changes: SimpleChanges) {
if (changes['dataFromCompTwo']) {
this.dataFromComp = this.dataFromCompTwo;
}
}
The issue arises when the component is instantiated twice, causing the data to double up. How can we ensure that only the latest sent data is displayed, regardless of which component it came from?
STACKBLITZ => I want to display the result "Here is the result" just once.