[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6FTQCVK0YVZH806WWP3MAXW":3,"skill-same:01M6FTQCVK0YVZH806WWP3MAXW":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":14,"repositoryHtmlUrl":45,"repositoryHomepageUrl":6,"ownerHtmlUrl":46,"ownerBlogUrl":47,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M6FTQCVK0YVZH806WWP3MAXW","angular-best-practices",null,"Angular performance optimization and best practices guide. Use when writing, reviewing, or refactoring Angular code for optimal performance, bundle size, and rendering efficiency.","reikiplanet\u002Fdaoskills","reikiplanet","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F96377599?v=4","01M6CVWCMD740YHQDK7E9QYBW4","Reiki Planet","01M6CVWCS4KXVA2CWFVJ43EAXK",0,"MIT","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fdevelopment\u002Fangular-best-practices\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"best practices","angular","angular best practices","bundle size","angular performance","rendering","bundle","efficiency","self","use","guide","writing","performance optimization","refactoring","Optimization","code","performance","safe","2026-11-10 10:12:30",false,"---\nname: angular-best-practices\ndescription: \"Angular performance optimization and best practices guide. Use when writing, reviewing, or refactoring Angular code for optimal performance, bundle size, and rendering efficiency.\"\nrisk: safe\nsource: self\n---\n\n# Angular Best Practices\n\nComprehensive performance optimization guide for Angular applications. Contains prioritized rules for eliminating performance bottlenecks, optimizing bundles, and improving rendering.\n\n## When to Apply\n\nReference these guidelines when:\n\n- Writing new Angular components or pages\n- Implementing data fetching patterns\n- Reviewing code for performance issues\n- Refactoring existing Angular code\n- Optimizing bundle size or load times\n- Configuring SSR\u002Fhydration\n\n---\n\n## Rule Categories by Priority\n\n| Priority | Category              | Impact     | Focus                           |\n| -------- | --------------------- | ---------- | ------------------------------- |\n| 1        | Change Detection      | CRITICAL   | Signals, OnPush, Zoneless       |\n| 2        | Async Waterfalls      | CRITICAL   | RxJS patterns, SSR preloading   |\n| 3        | Bundle Optimization   | CRITICAL   | Lazy loading, tree shaking      |\n| 4        | Rendering Performance | HIGH       | @defer, trackBy, virtualization |\n| 5        | Server-Side Rendering | HIGH       | Hydration, prerendering         |\n| 6        | Template Optimization | MEDIUM     | Control flow, pipes             |\n| 7        | State Management      | MEDIUM     | Signal patterns, selectors      |\n| 8        | Memory Management     | LOW-MEDIUM | Cleanup, subscriptions          |\n\n---\n\n## 1. Change Detection (CRITICAL)\n\n### Use OnPush Change Detection\n\n```typescript\n\u002F\u002F CORRECT - OnPush with Signals\n@Component({\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  template: `\u003Cdiv>{{ count() }}\u003C\u002Fdiv>`,\n})\nexport class CounterComponent {\n  count = signal(0);\n}\n\n\u002F\u002F WRONG - Default change detection\n@Component({\n  template: `\u003Cdiv>{{ count }}\u003C\u002Fdiv>`, \u002F\u002F Checked every cycle\n})\nexport class CounterComponent {\n  count = 0;\n}\n```\n\n### Prefer Signals Over Mutable Properties\n\n```typescript\n\u002F\u002F CORRECT - Signals trigger precise updates\n@Component({\n  template: `\n    \u003Ch1>{{ title() }}\u003C\u002Fh1>\n    \u003Cp>Count: {{ count() }}\u003C\u002Fp>\n  `,\n})\nexport class DashboardComponent {\n  title = signal(\"Dashboard\");\n  count = signal(0);\n}\n\n\u002F\u002F WRONG - Mutable properties require zone.js checks\n@Component({\n  template: `\n    \u003Ch1>{{ title }}\u003C\u002Fh1>\n    \u003Cp>Count: {{ count }}\u003C\u002Fp>\n  `,\n})\nexport class DashboardComponent {\n  title = \"Dashboard\";\n  count = 0;\n}\n```\n\n### Enable Zoneless for New Projects\n\n```typescript\n\u002F\u002F main.ts - Zoneless Angular (v20+)\nbootstrapApplication(AppComponent, {\n  providers: [provideZonelessChangeDetection()],\n});\n```\n\n**Benefits:**\n\n- No zone.js patches on async APIs\n- Smaller bundle (~15KB savings)\n- Clean stack traces for debugging\n- Better micro-frontend compatibility\n\n---\n\n## 2. Async Operations & Waterfalls (CRITICAL)\n\n### Eliminate Sequential Data Fetching\n\n```typescript\n\u002F\u002F WRONG - Nested subscriptions create waterfalls\nthis.route.params.subscribe((params) => {\n  \u002F\u002F 1. Wait for params\n  this.userService.getUser(params.id).subscribe((user) => {\n    \u002F\u002F 2. Wait for user\n    this.postsService.getPosts(user.id).subscribe((posts) => {\n      \u002F\u002F 3. Wait for posts\n    });\n  });\n});\n\n\u002F\u002F CORRECT - Parallel execution with forkJoin\nforkJoin({\n  user: this.userService.getUser(id),\n  posts: this.postsService.getPosts(id),\n}).subscribe((data) => {\n  \u002F\u002F Fetched in parallel\n});\n\n\u002F\u002F CORRECT - Flatten dependent calls with switchMap\nthis.route.params\n  .pipe(\n    map((p) => p.id),\n    switchMap((id) => this.userService.getUser(id)),\n  )\n  .subscribe();\n```\n\n### Avoid Client-Side Waterfalls in SSR\n\n```typescript\n\u002F\u002F CORRECT - Use resolvers or blocking hydration for critical data\nexport const route: Route = {\n  path: \"profile\u002F:id\",\n  resolve: { data: profileResolver }, \u002F\u002F Fetched on server before navigation\n  component: ProfileComponent,\n};\n\n\u002F\u002F WRONG - Component fetches data on init\nclass ProfileComponent implements OnInit {\n  ngOnInit() {\n    \u002F\u002F Starts ONLY after JS loads and component renders\n    this.http.get(\"\u002Fapi\u002Fprofile\").subscribe();\n  }\n}\n```\n\n---\n\n## 3. Bundle Optimization (CRITICAL)\n\n### Lazy Load Routes\n\n```typescript\n\u002F\u002F CORRECT - Lazy load feature routes\nexport const routes: Routes = [\n  {\n    path: \"admin\",\n    loadChildren: () =>\n      import(\".\u002Fadmin\u002Fadmin.routes\").then((m) => m.ADMIN_ROUTES),\n  },\n  {\n    path: \"dashboard\",\n    loadComponent: () =>\n      import(\".\u002Fdashboard\u002Fdashboard.component\").then(\n        (m) => m.DashboardComponent,\n      ),\n  },\n];\n\n\u002F\u002F WRONG - Eager loading everything\nimport { AdminModule } from \".\u002Fadmin\u002Fadmin.module\";\nexport const routes: Routes = [\n  { path: \"admin\", component: AdminComponent }, \u002F\u002F In main bundle\n];\n```\n\n### Use @defer for Heavy Components\n\n```html\n\u003C!-- CORRECT - Heavy component loads on demand -->\n@defer (on viewport) {\n\u003Capp-analytics-chart [data]=\"data()\" \u002F>\n} @placeholder {\n\u003Cdiv class=\"chart-skeleton\">\u003C\u002Fdiv>\n}\n\n\u003C!-- WRONG - Heavy component in initial bundle -->\n\u003Capp-analytics-chart [data]=\"data()\" \u002F>\n```\n\n### Avoid Barrel File Re-exports\n\n```typescript\n\u002F\u002F WRONG - Imports entire barrel, breaks tree-shaking\nimport { Button, Modal, Table } from \"@shared\u002Fcomponents\";\n\n\u002F\u002F CORRECT - Direct imports\nimport { Button } from \"@shared\u002Fcomponents\u002Fbutton\u002Fbutton.component\";\nimport { Modal } from \"@shared\u002Fcomponents\u002Fmodal\u002Fmodal.component\";\n```\n\n### Dynamic Import Third-Party Libraries\n\n```typescript\n\u002F\u002F CORRECT - Load heavy library on demand\nasync loadChart() {\n  const { Chart } = await import('chart.js');\n  this.chart = new Chart(this.canvas, config);\n}\n\n\u002F\u002F WRONG - Bundle Chart.js in main chunk\nimport { Chart } from 'chart.js';\n```\n\n---\n\n## 4. Rendering Performance (HIGH)\n\n### Always Use trackBy with @for\n\n```html\n\u003C!-- CORRECT - Efficient DOM updates -->\n@for (item of items(); track item.id) {\n\u003Capp-item-card [item]=\"item\" \u002F>\n}\n\n\u003C!-- WRONG - Entire list re-renders on any change -->\n@for (item of items(); track $index) {\n\u003Capp-item-card [item]=\"item\" \u002F>\n}\n```\n\n### Use Virtual Scrolling for Large Lists\n\n```typescript\nimport { CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll } from '@angular\u002Fcdk\u002Fscrolling';\n\n@Component({\n  imports: [CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll],\n  template: `\n    \u003Ccdk-virtual-scroll-viewport itemSize=\"50\" class=\"viewport\">\n      \u003Cdiv *cdkVirtualFor=\"let item of items\" class=\"item\">\n        {{ item.name }}\n      \u003C\u002Fdiv>\n    \u003C\u002Fcdk-virtual-scroll-viewport>\n  `\n})\n```\n\n### Prefer Pure Pipes Over Methods\n\n```typescript\n\u002F\u002F CORRECT - Pure pipe, memoized\n@Pipe({ name: 'filterActive', standalone: true, pure: true })\nexport class FilterActivePipe implements PipeTransform {\n  transform(items: Item[]): Item[] {\n    return items.filter(i => i.active);\n  }\n}\n\n\u002F\u002F Template\n@for (item of items() | filterActive; track item.id) { ... }\n\n\u002F\u002F WRONG - Method called every change detection\n@for (item of getActiveItems(); track item.id) { ... }\n```\n\n### Use computed() for Derived Data\n\n```typescript\n\u002F\u002F CORRECT - Computed, cached until dependencies change\nexport class ProductStore {\n  products = signal\u003CProduct[]>([]);\n  filter = signal('');\n\n  filteredProducts = computed(() => {\n    const f = this.filter().toLowerCase();\n    return this.products().filter(p =>\n      p.name.toLowerCase().includes(f)\n    );\n  });\n}\n\n\u002F\u002F WRONG - Recalculates every access\nget filteredProducts() {\n  return this.products.filter(p =>\n    p.name.toLowerCase().includes(this.filter)\n  );\n}\n```\n\n---\n\n## 5. Server-Side Rendering (HIGH)\n\n### Configure Incremental Hydration\n\n```typescript\n\u002F\u002F app.config.ts\nimport {\n  provideClientHydration,\n  withIncrementalHydration,\n} from \"@angular\u002Fplatform-browser\";\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideClientHydration(withIncrementalHydration(), withEventReplay()),\n  ],\n};\n```\n\n### Defer Non-Critical Content\n\n```html\n\u003C!-- Critical above-the-fold content -->\n\u003Capp-header \u002F>\n\u003Capp-hero \u002F>\n\n\u003C!-- Below-fold deferred with hydration triggers -->\n@defer (hydrate on viewport) {\n\u003Capp-product-grid \u002F>\n} @defer (hydrate on interaction) {\n\u003Capp-chat-widget \u002F>\n}\n```\n\n### Use TransferState for SSR Data\n\n```typescript\n@Injectable({ providedIn: \"root\" })\nexport class DataService {\n  private http = inject(HttpClient);\n  private transferState = inject(TransferState);\n  private platformId = inject(PLATFORM_ID);\n\n  getData(key: string): Observable\u003CData> {\n    const stateKey = makeStateKey\u003CData>(key);\n\n    if (isPlatformBrowser(this.platformId)) {\n      const cached = this.transferState.get(stateKey, null);\n      if (cached) {\n        this.transferState.remove(stateKey);\n        return of(cached);\n      }\n    }\n\n    return this.http.get\u003CData>(`\u002Fapi\u002F${key}`).pipe(\n      tap((data) => {\n        if (isPlatformServer(this.platformId)) {\n          this.transferState.set(stateKey, data);\n        }\n      }),\n    );\n  }\n}\n```\n\n---\n\n## 6. Template Optimization (MEDIUM)\n\n### Use New Control Flow Syntax\n\n```html\n\u003C!-- CORRECT - New control flow (faster, smaller bundle) -->\n@if (user()) {\n\u003Cspan>{{ user()!.name }}\u003C\u002Fspan>\n} @else {\n\u003Cspan>Guest\u003C\u002Fspan>\n} @for (item of items(); track item.id) {\n\u003Capp-item [item]=\"item\" \u002F>\n} @empty {\n\u003Cp>No items\u003C\u002Fp>\n}\n\n\u003C!-- WRONG - Legacy structural directives -->\n\u003Cspan *ngIf=\"user; else guest\">{{ user.name }}\u003C\u002Fspan>\n\u003Cng-template #guest>\u003Cspan>Guest\u003C\u002Fspan>\u003C\u002Fng-template>\n```\n\n### Avoid Complex Template Expressions\n\n```typescript\n\u002F\u002F CORRECT - Precompute in component\nclass Component {\n  items = signal\u003CItem[]>([]);\n  sortedItems = computed(() =>\n    [...this.items()].sort((a, b) => a.name.localeCompare(b.name))\n  );\n}\n\n\u002F\u002F Template\n@for (item of sortedItems(); track item.id) { ... }\n\n\u002F\u002F WRONG - Sorting in template every render\n@for (item of items() | sort:'name'; track item.id) { ... }\n```\n\n---\n\n## 7. State Management (MEDIUM)\n\n### Use Selectors to Prevent Re-renders\n\n```typescript\n\u002F\u002F CORRECT - Selective subscription\n@Component({\n  template: `\u003Cspan>{{ userName() }}\u003C\u002Fspan>`,\n})\nclass HeaderComponent {\n  private store = inject(Store);\n  \u002F\u002F Only re-renders when userName changes\n  userName = this.store.selectSignal(selectUserName);\n}\n\n\u002F\u002F WRONG - Subscribing to entire state\n@Component({\n  template: `\u003Cspan>{{ state().user.name }}\u003C\u002Fspan>`,\n})\nclass HeaderComponent {\n  private store = inject(Store);\n  \u002F\u002F Re-renders on ANY state change\n  state = toSignal(this.store);\n}\n```\n\n### Colocate State with Features\n\n```typescript\n\u002F\u002F CORRECT - Feature-scoped store\n@Injectable() \u002F\u002F NOT providedIn: 'root'\nexport class ProductStore { ... }\n\n@Component({\n  providers: [ProductStore], \u002F\u002F Scoped to component tree\n})\nexport class ProductPageComponent {\n  store = inject(ProductStore);\n}\n\n\u002F\u002F WRONG - Everything in global store\n@Injectable({ providedIn: 'root' })\nexport class GlobalStore {\n  \u002F\u002F Contains ALL app state - hard to tree-shake\n}\n```\n\n---\n\n## 8. Memory Management (LOW-MEDIUM)\n\n### Use takeUntilDestroyed for Subscriptions\n\n```typescript\nimport { takeUntilDestroyed } from '@angular\u002Fcore\u002Frxjs-interop';\n\n@Component({...})\nexport class DataComponent {\n  private destroyRef = inject(DestroyRef);\n\n  constructor() {\n    this.data$.pipe(\n      takeUntilDestroyed(this.destroyRef)\n    ).subscribe(data => this.process(data));\n  }\n}\n\n\u002F\u002F WRONG - Manual subscription management\nexport class DataComponent implements OnDestroy {\n  private subscription!: Subscription;\n\n  ngOnInit() {\n    this.subscription = this.data$.subscribe(...);\n  }\n\n  ngOnDestroy() {\n    this.subscription.unsubscribe(); \u002F\u002F Easy to forget\n  }\n}\n```\n\n### Prefer Signals Over Subscriptions\n\n```typescript\n\u002F\u002F CORRECT - No subscription needed\n@Component({\n  template: `\u003Cdiv>{{ data().name }}\u003C\u002Fdiv>`,\n})\nexport class Component {\n  data = toSignal(this.service.data$, { initialValue: null });\n}\n\n\u002F\u002F WRONG - Manual subscription\n@Component({\n  template: `\u003Cdiv>{{ data?.name }}\u003C\u002Fdiv>`,\n})\nexport class Component implements OnInit, OnDestroy {\n  data: Data | null = null;\n  private sub!: Subscription;\n\n  ngOnInit() {\n    this.sub = this.service.data$.subscribe((d) => (this.data = d));\n  }\n\n  ngOnDestroy() {\n    this.sub.unsubscribe();\n  }\n}\n```\n\n---\n\n## Quick Reference Checklist\n\n### New Component\n\n- [ ] `changeDetection: ChangeDetectionStrategy.OnPush`\n- [ ] `standalone: true`\n- [ ] Signals for state (`signal()`, `input()`, `output()`)\n- [ ] `inject()` for dependencies\n- [ ] `@for` with `track` expression\n\n### Performance Review\n\n- [ ] No methods in templates (use pipes or computed)\n- [ ] Large lists virtualized\n- [ ] Heavy components deferred\n- [ ] Routes lazy-loaded\n- [ ] Third-party libs dynamically imported\n\n### SSR Check\n\n- [ ] Hydration configured\n- [ ] Critical content renders first\n- [ ] Non-critical content uses `@defer (hydrate on ...)`\n- [ ] TransferState for server-fetched data\n\n---\n\n## Resources\n\n- [Angular Performance Guide](https:\u002F\u002Fangular.dev\u002Fbest-practices\u002Fperformance)\n- [Zoneless Angular](https:\u002F\u002Fangular.dev\u002Fguide\u002Fexperimental\u002Fzoneless)\n- [Angular SSR Guide](https:\u002F\u002Fangular.dev\u002Fguide\u002Fssr)\n- [Change Detection Deep Dive](https:\u002F\u002Fangular.dev\u002Fguide\u002Fchange-detection)\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n","# Angular Best Practices\n\nComprehensive performance optimization guide for Angular applications. Contains prioritized rules for eliminating performance bottlenecks, optimizing bundles, and improving rendering.\n\n## When to Apply\n\nReference these guidelines when:\n\n- Writing new Angular components or pages\n- Implementing data fetching patterns\n- Reviewing code for performance issues\n- Refactoring existing Angular code\n- Optimizing bundle size or load times\n- Configuring SSR\u002Fhydration\n\n---\n\n## Rule Categories by Priority\n\n| Priority | Category              | Impact     | Focus                           |\n| -------- | --------------------- | ---------- | ------------------------------- |\n| 1        | Change Detection      | CRITICAL   | Signals, OnPush, Zoneless       |\n| 2        | Async Waterfalls      | CRITICAL   | RxJS patterns, SSR preloading   |\n| 3        | Bundle Optimization   | CRITICAL   | Lazy loading, tree shaking      |\n| 4        | Rendering Performance | HIGH       | @defer, trackBy, virtualization |\n| 5        | Server-Side Rendering | HIGH       | Hydration, prerendering         |\n| 6        | Template Optimization | MEDIUM     | Control flow, pipes             |\n| 7        | State Management      | MEDIUM     | Signal patterns, selectors      |\n| 8        | Memory Management     | LOW-MEDIUM | Cleanup, subscriptions          |\n\n---\n\n## 1. Change Detection (CRITICAL)\n\n### Use OnPush Change Detection\n\n```typescript\n\u002F\u002F CORRECT - OnPush with Signals\n@Component({\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  template: `\u003Cdiv>{{ count() }}\u003C\u002Fdiv>`,\n})\nexport class CounterComponent {\n  count = signal(0);\n}\n\n\u002F\u002F WRONG - Default change detection\n@Component({\n  template: `\u003Cdiv>{{ count }}\u003C\u002Fdiv>`, \u002F\u002F Checked every cycle\n})\nexport class CounterComponent {\n  count = 0;\n}\n```\n\n### Prefer Signals Over Mutable Properties\n\n```typescript\n\u002F\u002F CORRECT - Signals trigger precise updates\n@Component({\n  template: `\n    \u003Ch1>{{ title() }}\u003C\u002Fh1>\n    \u003Cp>Count: {{ count() }}\u003C\u002Fp>\n  `,\n})\nexport class DashboardComponent {\n  title = signal(\"Dashboard\");\n  count = signal(0);\n}\n\n\u002F\u002F WRONG - Mutable properties require zone.js checks\n@Component({\n  template: `\n    \u003Ch1>{{ title }}\u003C\u002Fh1>\n    \u003Cp>Count: {{ count }}\u003C\u002Fp>\n  `,\n})\nexport class DashboardComponent {\n  title = \"Dashboard\";\n  count = 0;\n}\n```\n\n### Enable Zoneless for New Projects\n\n```typescript\n\u002F\u002F main.ts - Zoneless Angular (v20+)\nbootstrapApplication(AppComponent, {\n  providers: [provideZonelessChangeDetection()],\n});\n```\n\n**Benefits:**\n\n- No zone.js patches on async APIs\n- Smaller bundle (~15KB savings)\n- Clean stack traces for debugging\n- Better micro-frontend compatibility\n\n---\n\n## 2. Async Operations & Waterfalls (CRITICAL)\n\n### Eliminate Sequential Data Fetching\n\n```typescript\n\u002F\u002F WRONG - Nested subscriptions create waterfalls\nthis.route.params.subscribe((params) => {\n  \u002F\u002F 1. Wait for params\n  this.userService.getUser(params.id).subscribe((user) => {\n    \u002F\u002F 2. Wait for user\n    this.postsService.getPosts(user.id).subscribe((posts) => {\n      \u002F\u002F 3. Wait for posts\n    });\n  });\n});\n\n\u002F\u002F CORRECT - Parallel execution with forkJoin\nforkJoin({\n  user: this.userService.getUser(id),\n  posts: this.postsService.getPosts(id),\n}).subscribe((data) => {\n  \u002F\u002F Fetched in parallel\n});\n\n\u002F\u002F CORRECT - Flatten dependent calls with switchMap\nthis.route.params\n  .pipe(\n    map((p) => p.id),\n    switchMap((id) => this.userService.getUser(id)),\n  )\n  .subscribe();\n```\n\n### Avoid Client-Side Waterfalls in SSR\n\n```typescript\n\u002F\u002F CORRECT - Use resolvers or blocking hydration for critical data\nexport const route: Route = {\n  path: \"profile\u002F:id\",\n  resolve: { data: profileResolver }, \u002F\u002F Fetched on server before navigation\n  component: ProfileComponent,\n};\n\n\u002F\u002F WRONG - Component fetches data on init\nclass ProfileComponent implements OnInit {\n  ngOnInit() {\n    \u002F\u002F Starts ONLY after JS loads and component renders\n    this.http.get(\"\u002Fapi\u002Fprofile\").subscribe();\n  }\n}\n```\n\n---\n\n## 3. Bundle Optimization (CRITICAL)\n\n### Lazy Load Routes\n\n```typescript\n\u002F\u002F CORRECT - Lazy load feature routes\nexport const routes: Routes = [\n  {\n    path: \"admin\",\n    loadChildren: () =>\n      import(\".\u002Fadmin\u002Fadmin.routes\").then((m) => m.ADMIN_ROUTES),\n  },\n  {\n    path: \"dashboard\",\n    loadComponent: () =>\n      import(\".\u002Fdashboard\u002Fdashboard.component\").then(\n        (m) => m.DashboardComponent,\n      ),\n  },\n];\n\n\u002F\u002F WRONG - Eager loading everything\nimport { AdminModule } from \".\u002Fadmin\u002Fadmin.module\";\nexport const routes: Routes = [\n  { path: \"admin\", component: AdminComponent }, \u002F\u002F In main bundle\n];\n```\n\n### Use @defer for Heavy Components\n\n```html\n\u003C!-- CORRECT - Heavy component loads on demand -->\n@defer (on viewport) {\n\u003Capp-analytics-chart [data]=\"data()\" \u002F>\n} @placeholder {\n\u003Cdiv class=\"chart-skeleton\">\u003C\u002Fdiv>\n}\n\n\u003C!-- WRONG - Heavy component in initial bundle -->\n\u003Capp-analytics-chart [data]=\"data()\" \u002F>\n```\n\n### Avoid Barrel File Re-exports\n\n```typescript\n\u002F\u002F WRONG - Imports entire barrel, breaks tree-shaking\nimport { Button, Modal, Table } from \"@shared\u002Fcomponents\";\n\n\u002F\u002F CORRECT - Direct imports\nimport { Button } from \"@shared\u002Fcomponents\u002Fbutton\u002Fbutton.component\";\nimport { Modal } from \"@shared\u002Fcomponents\u002Fmodal\u002Fmodal.component\";\n```\n\n### Dynamic Import Third-Party Libraries\n\n```typescript\n\u002F\u002F CORRECT - Load heavy library on demand\nasync loadChart() {\n  const { Chart } = await import('chart.js');\n  this.chart = new Chart(this.canvas, config);\n}\n\n\u002F\u002F WRONG - Bundle Chart.js in main chunk\nimport { Chart } from 'chart.js';\n```\n\n---\n\n## 4. Rendering Performance (HIGH)\n\n### Always Use trackBy with @for\n\n```html\n\u003C!-- CORRECT - Efficient DOM updates -->\n@for (item of items(); track item.id) {\n\u003Capp-item-card [item]=\"item\" \u002F>\n}\n\n\u003C!-- WRONG - Entire list re-renders on any change -->\n@for (item of items(); track $index) {\n\u003Capp-item-card [item]=\"item\" \u002F>\n}\n```\n\n### Use Virtual Scrolling for Large Lists\n\n```typescript\nimport { CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll } from '@angular\u002Fcdk\u002Fscrolling';\n\n@Component({\n  imports: [CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll],\n  template: `\n    \u003Ccdk-virtual-scroll-viewport itemSize=\"50\" class=\"viewport\">\n      \u003Cdiv *cdkVirtualFor=\"let item of items\" class=\"item\">\n        {{ item.name }}\n      \u003C\u002Fdiv>\n    \u003C\u002Fcdk-virtual-scroll-viewport>\n  `\n})\n```\n\n### Prefer Pure Pipes Over Methods\n\n```typescript\n\u002F\u002F CORRECT - Pure pipe, memoized\n@Pipe({ name: 'filterActive', standalone: true, pure: true })\nexport class FilterActivePipe implements PipeTransform {\n  transform(items: Item[]): Item[] {\n    return items.filter(i => i.active);\n  }\n}\n\n\u002F\u002F Template\n@for (item of items() | filterActive; track item.id) { ... }\n\n\u002F\u002F WRONG - Method called every change detection\n@for (item of getActiveItems(); track item.id) { ... }\n```\n\n### Use computed() for Derived Data\n\n```typescript\n\u002F\u002F CORRECT - Computed, cached until dependencies change\nexport class ProductStore {\n  products = signal\u003CProduct[]>([]);\n  filter = signal('');\n\n  filteredProducts = computed(() => {\n    const f = this.filter().toLowerCase();\n    return this.products().filter(p =>\n      p.name.toLowerCase().includes(f)\n    );\n  });\n}\n\n\u002F\u002F WRONG - Recalculates every access\nget filteredProducts() {\n  return this.products.filter(p =>\n    p.name.toLowerCase().includes(this.filter)\n  );\n}\n```\n\n---\n\n## 5. Server-Side Rendering (HIGH)\n\n### Configure Incremental Hydration\n\n```typescript\n\u002F\u002F app.config.ts\nimport {\n  provideClientHydration,\n  withIncrementalHydration,\n} from \"@angular\u002Fplatform-browser\";\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideClientHydration(withIncrementalHydration(), withEventReplay()),\n  ],\n};\n```\n\n### Defer Non-Critical Content\n\n```html\n\u003C!-- Critical above-the-fold content -->\n\u003Capp-header \u002F>\n\u003Capp-hero \u002F>\n\n\u003C!-- Below-fold deferred with hydration triggers -->\n@defer (hydrate on viewport) {\n\u003Capp-product-grid \u002F>\n} @defer (hydrate on interaction) {\n\u003Capp-chat-widget \u002F>\n}\n```\n\n### Use TransferState for SSR Data\n\n```typescript\n@Injectable({ providedIn: \"root\" })\nexport class DataService {\n  private http = inject(HttpClient);\n  private transferState = inject(TransferState);\n  private platformId = inject(PLATFORM_ID);\n\n  getData(key: string): Observable\u003CData> {\n    const stateKey = makeStateKey\u003CData>(key);\n\n    if (isPlatformBrowser(this.platformId)) {\n      const cached = this.transferState.get(stateKey, null);\n      if (cached) {\n        this.transferState.remove(stateKey);\n        return of(cached);\n      }\n    }\n\n    return this.http.get\u003CData>(`\u002Fapi\u002F${key}`).pipe(\n      tap((data) => {\n        if (isPlatformServer(this.platformId)) {\n          this.transferState.set(stateKey, data);\n        }\n      }),\n    );\n  }\n}\n```\n\n---\n\n## 6. Template Optimization (MEDIUM)\n\n### Use New Control Flow Syntax\n\n```html\n\u003C!-- CORRECT - New control flow (faster, smaller bundle) -->\n@if (user()) {\n\u003Cspan>{{ user()!.name }}\u003C\u002Fspan>\n} @else {\n\u003Cspan>Guest\u003C\u002Fspan>\n} @for (item of items(); track item.id) {\n\u003Capp-item [item]=\"item\" \u002F>\n} @empty {\n\u003Cp>No items\u003C\u002Fp>\n}\n\n\u003C!-- WRONG - Legacy structural directives -->\n\u003Cspan *ngIf=\"user; else guest\">{{ user.name }}\u003C\u002Fspan>\n\u003Cng-template #guest>\u003Cspan>Guest\u003C\u002Fspan>\u003C\u002Fng-template>\n```\n\n### Avoid Complex Template Expressions\n\n```typescript\n\u002F\u002F CORRECT - Precompute in component\nclass Component {\n  items = signal\u003CItem[]>([]);\n  sortedItems = computed(() =>\n    [...this.items()].sort((a, b) => a.name.localeCompare(b.name))\n  );\n}\n\n\u002F\u002F Template\n@for (item of sortedItems(); track item.id) { ... }\n\n\u002F\u002F WRONG - Sorting in template every render\n@for (item of items() | sort:'name'; track item.id) { ... }\n```\n\n---\n\n## 7. State Management (MEDIUM)\n\n### Use Selectors to Prevent Re-renders\n\n```typescript\n\u002F\u002F CORRECT - Selective subscription\n@Component({\n  template: `\u003Cspan>{{ userName() }}\u003C\u002Fspan>`,\n})\nclass HeaderComponent {\n  private store = inject(Store);\n  \u002F\u002F Only re-renders when userName changes\n  userName = this.store.selectSignal(selectUserName);\n}\n\n\u002F\u002F WRONG - Subscribing to entire state\n@Component({\n  template: `\u003Cspan>{{ state().user.name }}\u003C\u002Fspan>`,\n})\nclass HeaderComponent {\n  private store = inject(Store);\n  \u002F\u002F Re-renders on ANY state change\n  state = toSignal(this.store);\n}\n```\n\n### Colocate State with Features\n\n```typescript\n\u002F\u002F CORRECT - Feature-scoped store\n@Injectable() \u002F\u002F NOT providedIn: 'root'\nexport class ProductStore { ... }\n\n@Component({\n  providers: [ProductStore], \u002F\u002F Scoped to component tree\n})\nexport class ProductPageComponent {\n  store = inject(ProductStore);\n}\n\n\u002F\u002F WRONG - Everything in global store\n@Injectable({ providedIn: 'root' })\nexport class GlobalStore {\n  \u002F\u002F Contains ALL app state - hard to tree-shake\n}\n```\n\n---\n\n## 8. Memory Management (LOW-MEDIUM)\n\n### Use takeUntilDestroyed for Subscriptions\n\n```typescript\nimport { takeUntilDestroyed } from '@angular\u002Fcore\u002Frxjs-interop';\n\n@Component({...})\nexport class DataComponent {\n  private destroyRef = inject(DestroyRef);\n\n  constructor() {\n    this.data$.pipe(\n      takeUntilDestroyed(this.destroyRef)\n    ).subscribe(data => this.process(data));\n  }\n}\n\n\u002F\u002F WRONG - Manual subscription management\nexport class DataComponent implements OnDestroy {\n  private subscription!: Subscription;\n\n  ngOnInit() {\n    this.subscription = this.data$.subscribe(...);\n  }\n\n  ngOnDestroy() {\n    this.subscription.unsubscribe(); \u002F\u002F Easy to forget\n  }\n}\n```\n\n### Prefer Signals Over Subscriptions\n\n```typescript\n\u002F\u002F CORRECT - No subscription needed\n@Component({\n  template: `\u003Cdiv>{{ data().name }}\u003C\u002Fdiv>`,\n})\nexport class Component {\n  data = toSignal(this.service.data$, { initialValue: null });\n}\n\n\u002F\u002F WRONG - Manual subscription\n@Component({\n  template: `\u003Cdiv>{{ data?.name }}\u003C\u002Fdiv>`,\n})\nexport class Component implements OnInit, OnDestroy {\n  data: Data | null = null;\n  private sub!: Subscription;\n\n  ngOnInit() {\n    this.sub = this.service.data$.subscribe((d) => (this.data = d));\n  }\n\n  ngOnDestroy() {\n    this.sub.unsubscribe();\n  }\n}\n```\n\n---\n\n## Quick Reference Checklist\n\n### New Component\n\n- [ ] `changeDetection: ChangeDetectionStrategy.OnPush`\n- [ ] `standalone: true`\n- [ ] Signals for state (`signal()`, `input()`, `output()`)\n- [ ] `inject()` for dependencies\n- [ ] `@for` with `track` expression\n\n### Performance Review\n\n- [ ] No methods in templates (use pipes or computed)\n- [ ] Large lists virtualized\n- [ ] Heavy components deferred\n- [ ] Routes lazy-loaded\n- [ ] Third-party libs dynamically imported\n\n### SSR Check\n\n- [ ] Hydration configured\n- [ ] Critical content renders first\n- [ ] Non-critical content uses `@defer (hydrate on ...)`\n- [ ] TransferState for server-fetched data\n\n---\n\n## Resources\n\n- [Angular Performance Guide](https:\u002F\u002Fangular.dev\u002Fbest-practices\u002Fperformance)\n- [Zoneless Angular](https:\u002F\u002Fangular.dev\u002Fguide\u002Fexperimental\u002Fzoneless)\n- [Angular SSR Guide](https:\u002F\u002Fangular.dev\u002Fguide\u002Fssr)\n- [Change Detection Deep Dive](https:\u002F\u002Fangular.dev\u002Fguide\u002Fchange-detection)\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n",{"name":5,"risk":36,"source":27,"description":7},"master","dff58085da947e81e8418c922055644bf0082b1b","development\u002Fangular-best-practices","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills","https:\u002F\u002Fgithub.com\u002Freikiplanet","https:\u002F\u002Fwww.reiki-planet.com","Reiki Planet Game","2026-03-29 06:02:29",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add reikiplanet\u002Fdaoskills --skill angular-best-practices",{"tool":56,"command":57},"bunx","bunx skills add reikiplanet\u002Fdaoskills --skill angular-best-practices",{"tool":59,"command":60},"pnpm","pnpm dlx skills add reikiplanet\u002Fdaoskills --skill angular-best-practices","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fdevelopment\u002Fangular-best-practices\u002FSKILL.md",true,[64,70],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"metadata.json","REFERENCE","参考文档",724,"https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fdevelopment\u002Fangular-best-practices\u002Fmetadata.json",{"path":71,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":72,"sourceHtmlUrl":73},"README.md",1845,"https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fdevelopment\u002Fangular-best-practices\u002FREADME.md",[75,101,112,126,146,169],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":37},"01M6G614JTEQJHPT8AKK3YQ18S","web-games","Web browser game development principles. Framework selection, WebGPU, optimization, PWA.","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fweb-games\u002FSKILL.md",[],[82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,33,97,98,99,100],"games","web games","web","grep","principles","selection","community","framework selection","edit","write","read","pwa","game","web browser","game development","framework","browser","development","webgpu",{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":37},"01M6G611H2YGV0GZFP90D38ZMJ","vr-ar","VR\u002FAR development principles. Comfort, interaction, performance requirements.","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fvr-ar\u002FSKILL.md",[],[108,109,99,110,111,88,90,91,92,85,35,86],"ar","vr ar","interaction","requirements",{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":37},"01M6G60XNMHAMV1SV0EJ1CX0AY","templates","Project scaffolding templates for new applications. Use when creating new projects from scratch. Contains 12 templates for various tech stacks.","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Ftemplates\u002FSKILL.md",[],[114,119,120,121,122,123,88,28,92,124,125,85],"project scaffolding","From Scratch","tech","project","scaffolding","projects","applications",{"skillNo":127,"name":128,"nameZh":6,"description":129,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":37},"01M6G60T0GATMK3Q5H8GDC1Z8S","wcag-audit-patterns","Conduct WCAG 2.2 accessibility audits with automated testing, manual verification, and remediation guidance. Use when auditing websites for accessibility, fixing WCAG violations, or implementing ac...","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fskills\u002Fsecurity\u002Fwcag-audit-patterns\u002FSKILL.md",[],[133,134,135,136,137,88,138,139,140,141,28,142,143,144,145],"wcag audit patterns","wcag audit","patterns","WCAG","audit","manual","with","automated testing","guidance","remediation","verification","accessibility","testing",{"skillNo":147,"name":148,"nameZh":6,"description":149,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":37},"01M6G60PMCHW1FRZ63F931QK3R","vulnerability-scanner","Advanced vulnerability analysis principles. OWASP 2025, Supply Chain Security, attack surface mapping, risk prioritization.","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fskills\u002Fsecurity\u002Fvulnerability-scanner\u002FSKILL.md",[],[153,154,155,156,157,158,159,160,88,92,85,161,86,162,163,164,165,166,167,168],"scanner","vulnerability scanner","vulnerability","prioritization","2025","mapping","chain","supply chain","Bash","analysis","risk","owasp","supply chain security","security","supply","advanced",{"skillNo":170,"name":171,"nameZh":6,"description":172,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":173,"categories":174,"keywords":175,"publishedAt":37},"01M6G60JZBB8DK0W3DSG1WNMZK","threat-modeling-expert","Expert in threat modeling methodologies, security architecture review, and risk assessment. Masters STRIDE, PASTA, attack trees, and security requirement extraction. Use for security architecture r...","https:\u002F\u002Fgithub.com\u002Freikiplanet\u002Fdaoskills\u002Fblob\u002Fmaster\u002Fskills\u002Fsecurity\u002Fthreat-modeling-expert\u002FSKILL.md",[],[176,177,178,179,180,181,182,183,166,28,184,185,186,88,187,188,189,163,190,191],"modeling","threat modeling expert","threat modeling","expert","threat","risk assessment","architecture review","architecture","security architecture review","trees","security architecture","security requirement extraction","assessment","extraction","review","stride"]