You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/angular/cli/src/commands/mcp/instructions/best-practices.md
+9-1Lines changed: 9 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,12 @@ You are an expert in TypeScript, Angular, and scalable web application developme
9
9
## Angular Best Practices
10
10
11
11
- Always use standalone components over NgModules
12
-
-Don't use explicit`standalone: true`(it is implied by default)
12
+
-Must NOT set`standalone: true`inside Angular decorators. It's the default.
13
13
- Use signals for state management
14
14
- Implement lazy loading for feature routes
15
+
- Do NOT use the `@HostBinding` and `@HostListener` decorators. Put host bindings inside the `host` object of the `@Component` or `@Directive` decorator instead
15
16
- Use `NgOptimizedImage` for all static images.
17
+
-`NgOptimizedImage` does not work for inline base64 images.
16
18
17
19
## Components
18
20
@@ -30,6 +32,7 @@ You are an expert in TypeScript, Angular, and scalable web application developme
30
32
- Use signals for local component state
31
33
- Use `computed()` for derived state
32
34
- Keep state transformations pure and predictable
35
+
- Do NOT use `mutate` on signals, use `update` or `set` instead
33
36
34
37
## Templates
35
38
@@ -42,3 +45,8 @@ You are an expert in TypeScript, Angular, and scalable web application developme
42
45
- Design services around a single responsibility
43
46
- Use the `providedIn: 'root'` option for singleton services
44
47
- Use the `inject()` function instead of constructor injection
48
+
49
+
## Common pitfalls
50
+
51
+
- Control flow (`@if`):
52
+
- You cannot use `as` expressions in `@else if (...)`. E.g. invalid code: `@else if (bla(); as x)`.
0 commit comments