Performance: Child to parent communication flow
MEDIUM IMPACT
This affects interaction responsiveness and rendering updates when child components send data or events to parent components.
import { Component, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'child-comp', template: `<button (click)="clicked.emit()">Click</button>` }) export class ChildComp { @Output() clicked = new EventEmitter<void>(); } // Parent template: <child-comp (clicked)="parentMethod()"></child-comp>
import { Component, Input } from '@angular/core'; @Component({ selector: 'child-comp', template: `<button (click)="notifyParent()">Click</button>` }) export class ChildComp { @Input() parentCallback!: () => void; notifyParent() { this.parentCallback(); } } // Parent template: <child-comp [parentCallback]="parentMethod"></child-comp>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Passing function via @Input | Triggers parent and child change detection | Multiple reflows if parent updates DOM | Higher paint cost due to unnecessary updates | [X] Bad |
| Using @Output EventEmitter | Triggers minimal change detection scoped to parent | Single reflow if DOM changes | Lower paint cost with targeted updates | [OK] Good |