Performance: ngAfterContentInit for projected content
MEDIUM IMPACT
This lifecycle hook affects the timing of when projected content is initialized and rendered, impacting initial rendering speed and interaction readiness.
ngAfterContentInit() {
// Minimal logic here
this.scheduleHeavyWorkOutsideAngular();
}
scheduleHeavyWorkOutsideAngular() {
setTimeout(() => {
// heavy work deferred after initial render
});
}ngAfterContentInit() {
this.projectedContent.forEach(item => {
// heavy DOM manipulation or complex logic
});
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous logic in ngAfterContentInit | Multiple DOM reads/writes | Triggers multiple reflows | High paint cost due to blocking | [X] Bad |
| Minimal logic with deferred heavy work | Minimal DOM operations initially | Single reflow after paint | Low paint cost, smoother rendering | [OK] Good |