create-huenei-template 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/templates/frontend/angular-base/.cursor/skills/angular-component/SKILL.md +288 -0
  2. package/dist/templates/frontend/angular-base/.cursor/skills/angular-component/references/component-patterns.md +358 -0
  3. package/dist/templates/frontend/angular-base/.cursor/skills/angular-di/SKILL.md +387 -0
  4. package/dist/templates/frontend/angular-base/.cursor/skills/angular-di/references/di-patterns.md +519 -0
  5. package/dist/templates/frontend/angular-base/.cursor/skills/angular-directives/SKILL.md +437 -0
  6. package/dist/templates/frontend/angular-base/.cursor/skills/angular-directives/references/directive-patterns.md +570 -0
  7. package/dist/templates/frontend/angular-base/.cursor/skills/angular-forms/SKILL.md +434 -0
  8. package/dist/templates/frontend/angular-base/.cursor/skills/angular-forms/references/form-patterns.md +398 -0
  9. package/dist/templates/frontend/angular-base/.cursor/skills/angular-http/SKILL.md +366 -0
  10. package/dist/templates/frontend/angular-base/.cursor/skills/angular-http/references/http-patterns.md +448 -0
  11. package/dist/templates/frontend/angular-base/.cursor/skills/angular-routing/SKILL.md +395 -0
  12. package/dist/templates/frontend/angular-base/.cursor/skills/angular-routing/references/routing-patterns.md +472 -0
  13. package/dist/templates/frontend/angular-base/.cursor/skills/angular-signals/SKILL.md +302 -0
  14. package/dist/templates/frontend/angular-base/.cursor/skills/angular-signals/references/signal-patterns.md +404 -0
  15. package/dist/templates/frontend/angular-base/.cursor/skills/angular-ssr/SKILL.md +435 -0
  16. package/dist/templates/frontend/angular-base/.cursor/skills/angular-ssr/references/ssr-patterns.md +497 -0
  17. package/dist/templates/frontend/angular-base/.cursor/skills/angular-testing/SKILL.md +660 -0
  18. package/dist/templates/frontend/angular-base/.cursor/skills/angular-testing/references/testing-patterns.md +707 -0
  19. package/dist/templates/frontend/angular-base/.cursor/skills/angular-tooling/SKILL.md +352 -0
  20. package/dist/templates/frontend/angular-base/.cursor/skills/angular-tooling/references/tooling-patterns.md +448 -0
  21. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-accessibility/SKILL.md +780 -0
  22. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-components/SKILL.md +718 -0
  23. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-design-systems/SKILL.md +612 -0
  24. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-layouts/SKILL.md +594 -0
  25. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/SKILL.md +432 -0
  26. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/references/animation-patterns.md +427 -0
  27. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/SKILL.md +354 -0
  28. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/references/troubleshooting-guide.md +306 -0
  29. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/SKILL.md +578 -0
  30. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/references/react-patterns.md +353 -0
  31. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/SKILL.md +608 -0
  32. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/advanced-theme-patterns.md +215 -0
  33. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/custom-utilities-guide.md +281 -0
  34. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-mobile-first/SKILL.md +768 -0
  35. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/SKILL.md +374 -0
  36. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/references/bundle-optimization.md +244 -0
  37. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-plugins/SKILL.md +505 -0
  38. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/SKILL.md +601 -0
  39. package/dist/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/references/advanced-responsive-patterns.md +485 -0
  40. package/dist/templates/frontend/angular-base/.cursor/skills/web-design-guidelines/SKILL.md +39 -0
  41. package/dist/templates/frontend/angular-base/package.json +0 -1
  42. package/dist/templates/frontend/angular-base/pnpm-lock.yaml +8183 -0
  43. package/package.json +1 -1
  44. package/templates/frontend/angular-base/.cursor/skills/angular-component/SKILL.md +288 -0
  45. package/templates/frontend/angular-base/.cursor/skills/angular-component/references/component-patterns.md +358 -0
  46. package/templates/frontend/angular-base/.cursor/skills/angular-di/SKILL.md +387 -0
  47. package/templates/frontend/angular-base/.cursor/skills/angular-di/references/di-patterns.md +519 -0
  48. package/templates/frontend/angular-base/.cursor/skills/angular-directives/SKILL.md +437 -0
  49. package/templates/frontend/angular-base/.cursor/skills/angular-directives/references/directive-patterns.md +570 -0
  50. package/templates/frontend/angular-base/.cursor/skills/angular-forms/SKILL.md +434 -0
  51. package/templates/frontend/angular-base/.cursor/skills/angular-forms/references/form-patterns.md +398 -0
  52. package/templates/frontend/angular-base/.cursor/skills/angular-http/SKILL.md +366 -0
  53. package/templates/frontend/angular-base/.cursor/skills/angular-http/references/http-patterns.md +448 -0
  54. package/templates/frontend/angular-base/.cursor/skills/angular-routing/SKILL.md +395 -0
  55. package/templates/frontend/angular-base/.cursor/skills/angular-routing/references/routing-patterns.md +472 -0
  56. package/templates/frontend/angular-base/.cursor/skills/angular-signals/SKILL.md +302 -0
  57. package/templates/frontend/angular-base/.cursor/skills/angular-signals/references/signal-patterns.md +404 -0
  58. package/templates/frontend/angular-base/.cursor/skills/angular-ssr/SKILL.md +435 -0
  59. package/templates/frontend/angular-base/.cursor/skills/angular-ssr/references/ssr-patterns.md +497 -0
  60. package/templates/frontend/angular-base/.cursor/skills/angular-testing/SKILL.md +660 -0
  61. package/templates/frontend/angular-base/.cursor/skills/angular-testing/references/testing-patterns.md +707 -0
  62. package/templates/frontend/angular-base/.cursor/skills/angular-tooling/SKILL.md +352 -0
  63. package/templates/frontend/angular-base/.cursor/skills/angular-tooling/references/tooling-patterns.md +448 -0
  64. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-accessibility/SKILL.md +780 -0
  65. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-components/SKILL.md +718 -0
  66. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-design-systems/SKILL.md +612 -0
  67. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-advanced-layouts/SKILL.md +594 -0
  68. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/SKILL.md +432 -0
  69. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-animations/references/animation-patterns.md +427 -0
  70. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/SKILL.md +354 -0
  71. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-debugging/references/troubleshooting-guide.md +306 -0
  72. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/SKILL.md +578 -0
  73. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-framework-integration/references/react-patterns.md +353 -0
  74. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/SKILL.md +608 -0
  75. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/advanced-theme-patterns.md +215 -0
  76. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-fundamentals-v4/references/custom-utilities-guide.md +281 -0
  77. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-mobile-first/SKILL.md +768 -0
  78. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/SKILL.md +374 -0
  79. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-performance/references/bundle-optimization.md +244 -0
  80. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-plugins/SKILL.md +505 -0
  81. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/SKILL.md +601 -0
  82. package/templates/frontend/angular-base/.cursor/skills/tailwindcss-responsive-darkmode/references/advanced-responsive-patterns.md +485 -0
  83. package/templates/frontend/angular-base/.cursor/skills/web-design-guidelines/SKILL.md +39 -0
  84. package/templates/frontend/angular-base/package.json +0 -1
  85. package/templates/frontend/angular-base/pnpm-lock.yaml +8183 -0
  86. package/templates/frontend/angular-base/package-lock.json +0 -13321
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-huenei-template",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-huenei-template": "bin/create-huenei-template.js"
@@ -0,0 +1,288 @@
1
+ ---
2
+ name: angular-component
3
+ description: Create modern Angular standalone components following v20+ best practices. Use for building UI components with signal-based inputs/outputs, OnPush change detection, host bindings, content projection, and lifecycle hooks. Triggers on component creation, refactoring class-based inputs to signals, adding host bindings, or implementing accessible interactive components.
4
+ ---
5
+
6
+ # Angular Component
7
+
8
+ Create standalone components for Angular v20+. Components are standalone by default—do NOT set `standalone: true`.
9
+
10
+ ## Component Structure
11
+
12
+ ```typescript
13
+ import { Component, ChangeDetectionStrategy, input, output, computed } from '@angular/core';
14
+
15
+ @Component({
16
+ selector: 'app-user-card',
17
+ changeDetection: ChangeDetectionStrategy.OnPush,
18
+ host: {
19
+ 'class': 'user-card',
20
+ '[class.active]': 'isActive()',
21
+ '(click)': 'handleClick()',
22
+ },
23
+ template: `
24
+ <img [src]="avatarUrl()" [alt]="name() + ' avatar'" />
25
+ <h2>{{ name() }}</h2>
26
+ @if (showEmail()) {
27
+ <p>{{ email() }}</p>
28
+ }
29
+ `,
30
+ styles: `
31
+ :host { display: block; }
32
+ :host.active { border: 2px solid blue; }
33
+ `,
34
+ })
35
+ export class UserCard {
36
+ // Required input
37
+ name = input.required<string>();
38
+
39
+ // Optional input with default
40
+ email = input<string>('');
41
+ showEmail = input(false);
42
+
43
+ // Input with transform
44
+ isActive = input(false, { transform: booleanAttribute });
45
+
46
+ // Computed from inputs
47
+ avatarUrl = computed(() => `https://api.example.com/avatar/${this.name()}`);
48
+
49
+ // Output
50
+ selected = output<string>();
51
+
52
+ handleClick() {
53
+ this.selected.emit(this.name());
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## Signal Inputs
59
+
60
+ ```typescript
61
+ // Required - must be provided by parent
62
+ name = input.required<string>();
63
+
64
+ // Optional with default value
65
+ count = input(0);
66
+
67
+ // Optional without default (undefined allowed)
68
+ label = input<string>();
69
+
70
+ // With alias for template binding
71
+ size = input('medium', { alias: 'buttonSize' });
72
+
73
+ // With transform function
74
+ disabled = input(false, { transform: booleanAttribute });
75
+ value = input(0, { transform: numberAttribute });
76
+ ```
77
+
78
+ ## Signal Outputs
79
+
80
+ ```typescript
81
+ import { output, outputFromObservable } from '@angular/core';
82
+
83
+ // Basic output
84
+ clicked = output<void>();
85
+ selected = output<Item>();
86
+
87
+ // With alias
88
+ valueChange = output<number>({ alias: 'change' });
89
+
90
+ // From Observable (for RxJS interop)
91
+ scroll$ = new Subject<number>();
92
+ scrolled = outputFromObservable(this.scroll$);
93
+
94
+ // Emit values
95
+ this.clicked.emit();
96
+ this.selected.emit(item);
97
+ ```
98
+
99
+ ## Host Bindings
100
+
101
+ Use the `host` object in `@Component`—do NOT use `@HostBinding` or `@HostListener` decorators.
102
+
103
+ ```typescript
104
+ @Component({
105
+ selector: 'app-button',
106
+ host: {
107
+ // Static attributes
108
+ 'role': 'button',
109
+
110
+ // Dynamic class bindings
111
+ '[class.primary]': 'variant() === "primary"',
112
+ '[class.disabled]': 'disabled()',
113
+
114
+ // Dynamic style bindings
115
+ '[style.--btn-color]': 'color()',
116
+
117
+ // Attribute bindings
118
+ '[attr.aria-disabled]': 'disabled()',
119
+ '[attr.tabindex]': 'disabled() ? -1 : 0',
120
+
121
+ // Event listeners
122
+ '(click)': 'onClick($event)',
123
+ '(keydown.enter)': 'onClick($event)',
124
+ '(keydown.space)': 'onClick($event)',
125
+ },
126
+ template: `<ng-content />`,
127
+ })
128
+ export class Button {
129
+ variant = input<'primary' | 'secondary'>('primary');
130
+ disabled = input(false, { transform: booleanAttribute });
131
+ color = input('#007bff');
132
+
133
+ clicked = output<void>();
134
+
135
+ onClick(event: Event) {
136
+ if (!this.disabled()) {
137
+ this.clicked.emit();
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ ## Content Projection
144
+
145
+ ```typescript
146
+ @Component({
147
+ selector: 'app-card',
148
+ template: `
149
+ <header>
150
+ <ng-content select="[card-header]" />
151
+ </header>
152
+ <main>
153
+ <ng-content />
154
+ </main>
155
+ <footer>
156
+ <ng-content select="[card-footer]" />
157
+ </footer>
158
+ `,
159
+ })
160
+ export class Card {}
161
+
162
+ // Usage:
163
+ // <app-card>
164
+ // <h2 card-header>Title</h2>
165
+ // <p>Main content</p>
166
+ // <button card-footer>Action</button>
167
+ // </app-card>
168
+ ```
169
+
170
+ ## Lifecycle Hooks
171
+
172
+ ```typescript
173
+ import { OnDestroy, OnInit, afterNextRender, afterRender } from '@angular/core';
174
+
175
+ export class My implements OnInit, OnDestroy {
176
+ constructor() {
177
+ // For DOM manipulation after render (SSR-safe)
178
+ afterNextRender(() => {
179
+ // Runs once after first render
180
+ });
181
+
182
+ afterRender(() => {
183
+ // Runs after every render
184
+ });
185
+ }
186
+
187
+ ngOnInit() { /* Component initialized */ }
188
+ ngOnDestroy() { /* Cleanup */ }
189
+ }
190
+ ```
191
+
192
+ ## Accessibility Requirements
193
+
194
+ Components MUST:
195
+ - Pass AXE accessibility checks
196
+ - Meet WCAG AA standards
197
+ - Include proper ARIA attributes for interactive elements
198
+ - Support keyboard navigation
199
+ - Maintain visible focus indicators
200
+
201
+ ```typescript
202
+ @Component({
203
+ selector: 'app-toggle',
204
+ host: {
205
+ 'role': 'switch',
206
+ '[attr.aria-checked]': 'checked()',
207
+ '[attr.aria-label]': 'label()',
208
+ 'tabindex': '0',
209
+ '(click)': 'toggle()',
210
+ '(keydown.enter)': 'toggle()',
211
+ '(keydown.space)': 'toggle(); $event.preventDefault()',
212
+ },
213
+ template: `<span class="toggle-track"><span class="toggle-thumb"></span></span>`,
214
+ })
215
+ export class Toggle {
216
+ label = input.required<string>();
217
+ checked = input(false, { transform: booleanAttribute });
218
+ checkedChange = output<boolean>();
219
+
220
+ toggle() {
221
+ this.checkedChange.emit(!this.checked());
222
+ }
223
+ }
224
+ ```
225
+
226
+ ## Template Syntax
227
+
228
+ Use native control flow—do NOT use `*ngIf`, `*ngFor`, `*ngSwitch`.
229
+
230
+ ```html
231
+ <!-- Conditionals -->
232
+ @if (isLoading()) {
233
+ <app-spinner />
234
+ } @else if (error()) {
235
+ <app-error [message]="error()" />
236
+ } @else {
237
+ <app-content [data]="data()" />
238
+ }
239
+
240
+ <!-- Loops -->
241
+ @for (item of items(); track item.id) {
242
+ <app-item [item]="item" />
243
+ } @empty {
244
+ <p>No items found</p>
245
+ }
246
+
247
+ <!-- Switch -->
248
+ @switch (status()) {
249
+ @case ('pending') { <span>Pending</span> }
250
+ @case ('active') { <span>Active</span> }
251
+ @default { <span>Unknown</span> }
252
+ }
253
+ ```
254
+
255
+ ## Class and Style Bindings
256
+
257
+ Do NOT use `ngClass` or `ngStyle`. Use direct bindings:
258
+
259
+ ```html
260
+ <!-- Class bindings -->
261
+ <div [class.active]="isActive()">Single class</div>
262
+ <div [class]="classString()">Class string</div>
263
+
264
+ <!-- Style bindings -->
265
+ <div [style.color]="textColor()">Styled text</div>
266
+ <div [style.width.px]="width()">With unit</div>
267
+ ```
268
+
269
+ ## Images
270
+
271
+ Use `NgOptimizedImage` for static images:
272
+
273
+ ```typescript
274
+ import { NgOptimizedImage } from '@angular/common';
275
+
276
+ @Component({
277
+ imports: [NgOptimizedImage],
278
+ template: `
279
+ <img ngSrc="/assets/hero.jpg" width="800" height="600" priority />
280
+ <img [ngSrc]="imageUrl()" width="200" height="200" />
281
+ `,
282
+ })
283
+ export class Hero {
284
+ imageUrl = input.required<string>();
285
+ }
286
+ ```
287
+
288
+ For detailed patterns, see [references/component-patterns.md](references/component-patterns.md).
@@ -0,0 +1,358 @@
1
+ # Angular Component Patterns
2
+
3
+ ## Table of Contents
4
+ - [Model Inputs (Two-Way Binding)](#model-inputs-two-way-binding)
5
+ - [View Queries](#view-queries)
6
+ - [Content Queries](#content-queries)
7
+ - [Dependency Injection in Components](#dependency-injection-in-components)
8
+ - [Component Communication Patterns](#component-communication-patterns)
9
+ - [Dynamic Components](#dynamic-components)
10
+
11
+ ## Model Inputs (Two-Way Binding)
12
+
13
+ For two-way binding with `[(value)]` syntax:
14
+
15
+ ```typescript
16
+ import { Component, model } from '@angular/core';
17
+
18
+ @Component({
19
+ selector: 'app-slider',
20
+ host: {
21
+ '(input)': 'onInput($event)',
22
+ },
23
+ template: `
24
+ <input
25
+ type="range"
26
+ [value]="value()"
27
+ [min]="min()"
28
+ [max]="max()"
29
+ />
30
+ <span>{{ value() }}</span>
31
+ `,
32
+ })
33
+ export class Slider {
34
+ // Model creates both input and output
35
+ value = model(0);
36
+ min = input(0);
37
+ max = input(100);
38
+
39
+ onInput(event: Event) {
40
+ const target = event.target as HTMLInputElement;
41
+ this.value.set(Number(target.value));
42
+ }
43
+ }
44
+
45
+ // Usage: <app-slider [(value)]="sliderValue" />
46
+ ```
47
+
48
+ Required model:
49
+
50
+ ```typescript
51
+ value = model.required<number>();
52
+ ```
53
+
54
+ ## View Queries
55
+
56
+ Query elements and components in the template:
57
+
58
+ ```typescript
59
+ import { Component, viewChild, viewChildren, ElementRef } from '@angular/core';
60
+
61
+ @Component({
62
+ selector: 'app-gallery',
63
+ template: `
64
+ <div #container class="gallery">
65
+ @for (image of images(); track image.id) {
66
+ <app-image-card [image]="image" />
67
+ }
68
+ </div>
69
+ `,
70
+ })
71
+ export class Gallery {
72
+ images = input.required<Image[]>();
73
+
74
+ // Query single element
75
+ container = viewChild.required<ElementRef<HTMLDivElement>>('container');
76
+
77
+ // Query single component (optional)
78
+ firstCard = viewChild(ImageCard);
79
+
80
+ // Query all matching components
81
+ allCards = viewChildren(ImageCard);
82
+ }
83
+ ```
84
+
85
+ ## Content Queries
86
+
87
+ Query projected content:
88
+
89
+ ```typescript
90
+ import { Component, contentChild, contentChildren, effect, signal } from '@angular/core';
91
+
92
+ @Component({
93
+ selector: 'app-tabs',
94
+ template: `
95
+ <div class="tab-headers">
96
+ @for (tab of tabs(); track tab.label()) {
97
+ <button
98
+ [class.active]="tab === activeTab()"
99
+ (click)="selectTab(tab)"
100
+ >
101
+ {{ tab.label() }}
102
+ </button>
103
+ }
104
+ </div>
105
+ <div class="tab-content">
106
+ <ng-content />
107
+ </div>
108
+ `,
109
+ })
110
+ export class Tabs {
111
+ // Query all projected Tab children
112
+ tabs = contentChildren(Tab);
113
+
114
+ // Query single projected element
115
+ header = contentChild('tabHeader');
116
+
117
+ activeTab = signal<Tab | undefined>(undefined);
118
+
119
+ constructor() {
120
+ // Set first tab as active when tabs are available
121
+ effect(() => {
122
+ const firstTab = this.tabs()[0];
123
+ if (firstTab && !this.activeTab()) {
124
+ this.activeTab.set(firstTab);
125
+ }
126
+ });
127
+ }
128
+
129
+ selectTab(tab: Tab) {
130
+ this.activeTab.set(tab);
131
+ }
132
+ }
133
+
134
+ @Component({
135
+ selector: 'app-tab',
136
+ template: `<ng-content />`,
137
+ host: {
138
+ '[class.active]': 'isActive()',
139
+ '[style.display]': 'isActive() ? "block" : "none"',
140
+ },
141
+ })
142
+ export class Tab {
143
+ label = input.required<string>();
144
+ isActive = input(false);
145
+ }
146
+ ```
147
+
148
+ ## Dependency Injection in Components
149
+
150
+ Use `inject()` function instead of constructor injection:
151
+
152
+ ```typescript
153
+ import { Component, inject } from '@angular/core';
154
+ import { Router } from '@angular/router';
155
+
156
+ @Component({
157
+ selector: 'app-dashboard',
158
+ template: `...`,
159
+ })
160
+ export class Dashboard {
161
+ private router = inject(Router);
162
+ private userService = inject(User);
163
+ private config = inject(APP_CONFIG);
164
+
165
+ // Optional injection
166
+ private analytics = inject(Analytics, { optional: true });
167
+
168
+ // Self-only injection
169
+ private localService = inject(Local, { self: true });
170
+
171
+ navigateToProfile() {
172
+ this.router.navigate(['/profile']);
173
+ }
174
+ }
175
+ ```
176
+
177
+ ## Component Communication Patterns
178
+
179
+ ### Parent to Child (Inputs)
180
+
181
+ ```typescript
182
+ // Parent
183
+ @Component({
184
+ template: `<app-child [data]="parentData()" [config]="config" />`,
185
+ })
186
+ export class Parent {
187
+ parentData = signal({ name: 'Test' });
188
+ config = { theme: 'dark' };
189
+ }
190
+
191
+ // Child
192
+ @Component({ selector: 'app-child' })
193
+ export class Child {
194
+ data = input.required<Data>();
195
+ config = input<Config>();
196
+ }
197
+ ```
198
+
199
+ ### Child to Parent (Outputs)
200
+
201
+ ```typescript
202
+ // Child
203
+ @Component({
204
+ selector: 'app-child',
205
+ template: `<button (click)="save()">Save</button>`,
206
+ })
207
+ export class Child {
208
+ saved = output<Data>();
209
+
210
+ save() {
211
+ this.saved.emit({ id: 1, name: 'Item' });
212
+ }
213
+ }
214
+
215
+ // Parent
216
+ @Component({
217
+ template: `<app-child (saved)="onSaved($event)" />`,
218
+ })
219
+ export class Parent {
220
+ onSaved(data: Data) {
221
+ console.log('Saved:', data);
222
+ }
223
+ }
224
+ ```
225
+
226
+ ### Shared Service Pattern
227
+
228
+ ```typescript
229
+ // Shared state service
230
+ @Injectable({ providedIn: 'root' })
231
+ export class Cart {
232
+ private items = signal<CartItem[]>([]);
233
+
234
+ readonly items$ = this.items.asReadonly();
235
+ readonly total = computed(() =>
236
+ this.items().reduce((sum, item) => sum + item.price, 0)
237
+ );
238
+
239
+ addItem(item: CartItem) {
240
+ this.items.update(items => [...items, item]);
241
+ }
242
+
243
+ removeItem(id: string) {
244
+ this.items.update(items => items.filter(i => i.id !== id));
245
+ }
246
+ }
247
+
248
+ // Component A
249
+ @Component({ template: `<button (click)="add()">Add</button>` })
250
+ export class Product {
251
+ private cart = inject(Cart);
252
+ product = input.required<Product>();
253
+
254
+ add() {
255
+ this.cart.addItem({ ...this.product(), quantity: 1 });
256
+ }
257
+ }
258
+
259
+ // Component B
260
+ @Component({ template: `<span>Total: {{ cart.total() }}</span>` })
261
+ export class CartSummary {
262
+ cart = inject(Cart);
263
+ }
264
+ ```
265
+
266
+ ## Dynamic Components
267
+
268
+ Using `@defer` for lazy loading:
269
+
270
+ ```typescript
271
+ @Component({
272
+ template: `
273
+ @defer (on viewport) {
274
+ <app-heavy-chart [data]="chartData()" />
275
+ } @placeholder {
276
+ <div class="chart-placeholder">Loading chart...</div>
277
+ } @loading (minimum 500ms) {
278
+ <app-spinner />
279
+ } @error {
280
+ <p>Failed to load chart</p>
281
+ }
282
+ `,
283
+ })
284
+ export class Dashboard {
285
+ chartData = input.required<ChartData>();
286
+ }
287
+ ```
288
+
289
+ Defer triggers:
290
+ - `on viewport` - When element enters viewport
291
+ - `on idle` - When browser is idle
292
+ - `on interaction` - On user interaction (click, focus)
293
+ - `on hover` - On mouse hover
294
+ - `on immediate` - Immediately after non-deferred content
295
+ - `on timer(500ms)` - After specified delay
296
+ - `when condition` - When expression becomes true
297
+
298
+ ```typescript
299
+ @Component({
300
+ template: `
301
+ @defer (on interaction; prefetch on idle) {
302
+ <app-comments [postId]="postId()" />
303
+ } @placeholder {
304
+ <button>Load Comments</button>
305
+ }
306
+ `,
307
+ })
308
+ export class Post {
309
+ postId = input.required<string>();
310
+ }
311
+ ```
312
+
313
+ ## Attribute Directives on Components
314
+
315
+ ```typescript
316
+ @Directive({
317
+ selector: '[appHighlight]',
318
+ host: {
319
+ '[style.backgroundColor]': 'color()',
320
+ },
321
+ })
322
+ export class Highlight {
323
+ color = input('yellow', { alias: 'appHighlight' });
324
+ }
325
+
326
+ // Usage on component
327
+ @Component({
328
+ imports: [Highlight],
329
+ template: `<app-card appHighlight="lightblue" />`,
330
+ })
331
+ export class Page {}
332
+ ```
333
+
334
+ ## Error Boundaries
335
+
336
+ ```typescript
337
+ @Component({
338
+ selector: 'app-error-boundary',
339
+ template: `
340
+ @if (hasError()) {
341
+ <div class="error">
342
+ <h3>Something went wrong</h3>
343
+ <button (click)="retry()">Retry</button>
344
+ </div>
345
+ } @else {
346
+ <ng-content />
347
+ }
348
+ `,
349
+ })
350
+ export class ErrorBoundary {
351
+ hasError = signal(false);
352
+ private errorHandler = inject(ErrorHandler);
353
+
354
+ retry() {
355
+ this.hasError.set(false);
356
+ }
357
+ }
358
+ ```