Performance: Why component communication matters
Component communication affects how fast and smoothly data flows between parts of the app, impacting interaction speed and visual updates.
Use Angular signals or a shared service with RxJS observables to manage state and communicate efficiently between components.
Parent component uses multiple EventEmitters and @Input properties with frequent change detection cycles triggering many updates.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| EventEmitters with default change detection | Many DOM updates | Multiple reflows per event | High paint cost due to frequent updates | [X] Bad |
| Signals or RxJS with OnPush change detection | Minimal DOM updates | Single or no reflows per event | Low paint cost with batched updates | [OK] Good |
[] to bind data from parent to child.[data]="parentData" correctly passes parentData to child's @Input() property.Child component TS:
@Output() notify = new EventEmitter<string>();
sendNotification() { this.notify.emit('Hello'); }
Parent component template:
<child-comp (notify)="onNotify($event)"></child-comp>
Parent component TS:
onNotify(message: string) { console.log(message); }
notify.emit('Hello').(notify)="onNotify($event)", so onNotify receives 'Hello'.Parent template:
<child-comp data="parentData"></child-comp>
Child component TS:
@Input() data: string;
data="parentData" passes a string literal, not the variable value.Pass the test and this pattern moves unknown