Performance: What is Angular
Angular affects page load speed and rendering performance by how it manages DOM updates and component rendering.
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<div *ngFor=\"let item of visibleItems\">{{item}}</div>` }) export class AppComponent { items = Array(1000).fill('Item'); visibleItems = this.items.slice(0, 20); // virtual scroll or pagination }
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<div *ngFor=\"let item of items\">{{item}}</div>` }) export class AppComponent { items = Array(1000).fill('Item'); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Rendering large lists without optimization | 1000+ nodes | 1000+ reflows | High paint cost | [X] Bad |
| Rendering small visible subset with virtual scroll | 20 nodes | 20 reflows | Low paint cost | [OK] Good |
@Component({ standalone: true, selector: 'app-sample', template: 'Hello
' }) export class SampleComponent {} matches the correct syntax; A is plain function, B is for modules, D is invalid class extension.@Component({ standalone: true, selector: 'app-counter', template: `<button (click)='count = count + 1'>Increment</button><p>Count: {{count}}</p>` }) export class CounterComponent { count = 0; }@Component({ selector: 'app-test', template: '<p>Test</p>' }) export class TestComponent { count = 0; increment() { this.count++; } }<button (click)='increment'>Add</button><p>Count: {{count}}</p>Pass the test and this pattern moves unknown