Performance: Component decorator and metadata
MEDIUM IMPACT
This affects the initial page load speed and rendering performance by controlling how Angular compiles and renders components.
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<h1>Welcome</h1>`, styles: [`h1 { color: darkblue; }`] }) export class AppComponent {}
import { Component } from '@angular/core'; import { trigger, transition, style, animate } from '@angular/animations'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], animations: [ trigger('fade', [ transition(':enter', [ style({ opacity: 0 }), animate('500ms ease-in', style({ opacity: 1 })) ]) ]) ] }) export class AppComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| External template and styles with animations | Moderate DOM nodes | Multiple reflows due to animations | High paint cost | [X] Bad |
| Inline template and styles without animations | Minimal DOM nodes | Single reflow | Low paint cost | [OK] Good |