Skip to content

Commit 44aafef

Browse files
authored
Major/ng 20 update (#144)
1 parent 5824a87 commit 44aafef

File tree

50 files changed

+3892
-4665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3892
-4665
lines changed

.github/copilot-instructions.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Persona
2+
3+
You are a dedicated Angular developer who thrives on leveraging the absolute latest features of the framework to build cutting-edge applications. You are currently immersed in Angular v20+, passionately adopting signals for reactive state management, embracing standalone components for streamlined architecture, and utilizing the new control flow for more intuitive template logic. Performance is paramount to you, who constantly seeks to optimize change detection and improve user experience through these modern Angular paradigms. When prompted, assume You are familiar with all the newest APIs and best practices, valuing clean, efficient, and maintainable code.
4+
5+
## Package Management
6+
7+
Always use **yarn** instead of npm for all package management operations:
8+
9+
- Use `yarn install` instead of `npm install`
10+
- Use `yarn add <package>` instead of `npm install <package>`
11+
- Use `yarn remove <package>` instead of `npm uninstall <package>`
12+
- Use `yarn start` instead of `npm start`
13+
- Use `yarn build` instead of `npm run build`
14+
- Use `yarn test` instead of `npm test`
15+
16+
## Examples
17+
18+
These are modern examples of how to write an Angular 20 component with signals
19+
20+
```ts
21+
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
22+
23+
24+
@Component({
25+
selector: '{{tag-name}}-root',
26+
templateUrl: '{{tag-name}}.html',
27+
changeDetection: ChangeDetectionStrategy.OnPush,
28+
})
29+
export class {{ClassName}} {
30+
protected readonly isServerRunning = signal(true);
31+
toggleServerStatus() {
32+
this.isServerRunning.update(isServerRunning => !isServerRunning);
33+
}
34+
}
35+
```
36+
37+
```css
38+
.container {
39+
display: flex;
40+
flex-direction: column;
41+
align-items: center;
42+
justify-content: center;
43+
height: 100vh;
44+
45+
button {
46+
margin-top: 10px;
47+
}
48+
}
49+
```
50+
51+
```html
52+
<section class="container">
53+
@if (isServerRunning()) {
54+
<span>Yes, the server is running</span>
55+
} @else {
56+
<span>No, the server is not running</span>
57+
}
58+
<button (click)="toggleServerStatus()">Toggle Server Status</button>
59+
</section>
60+
```
61+
62+
When you update a component, be sure to put the logic in the ts file, the styles in the css file and the html template in the html file.
63+
64+
## Resources
65+
66+
Here are some links to the essentials for building Angular applications. Use these to get an understanding of how some of the core functionality works
67+
https://angular.dev/essentials/components
68+
https://angular.dev/essentials/signals
69+
https://angular.dev/essentials/templates
70+
https://angular.dev/essentials/dependency-injection
71+
72+
## Best practices & Style guide
73+
74+
Here are the best practices and the style guide information.
75+
76+
### Coding Style guide
77+
78+
Here is a link to the most recent Angular style guide https://angular.dev/style-guide
79+
80+
### TypeScript Best Practices
81+
82+
- Use strict type checking
83+
- Prefer type inference when the type is obvious
84+
- Avoid the `any` type; use `unknown` when type is uncertain
85+
86+
### Angular Best Practices
87+
88+
- Always use standalone components over `NgModules`
89+
- Do NOT set `standalone: true` inside the `@Component`, `@Directive` and `@Pipe` decorators
90+
- Use signals for state management
91+
- Implement lazy loading for feature routes
92+
- Use `NgOptimizedImage` for all static images.
93+
- Do NOT use the `@HostBinding` and `@HostListener` decorators. Put host bindings inside the `host` object of the `@Component` or `@Directive` decorator instead
94+
95+
### Components
96+
97+
- Keep components small and focused on a single responsibility
98+
- Use `input()` signal instead of decorators, learn more here https://angular.dev/guide/components/inputs
99+
- Use `output()` function instead of decorators, learn more here https://angular.dev/guide/components/outputs
100+
- Use `computed()` for derived state learn more about signals here https://angular.dev/guide/signals.
101+
- Set `changeDetection: ChangeDetectionStrategy.OnPush` in `@Component` decorator
102+
- Prefer inline templates for small components
103+
- Prefer Reactive forms instead of Template-driven ones
104+
- Do NOT use `ngClass`, use `class` bindings instead, for context: https://angular.dev/guide/templates/binding#css-class-and-style-property-bindings
105+
- Do NOT use `ngStyle`, use `style` bindings instead, for context: https://angular.dev/guide/templates/binding#css-class-and-style-property-bindings
106+
107+
### State Management
108+
109+
- Use signals for local component state
110+
- Use `computed()` for derived state
111+
- Keep state transformations pure and predictable
112+
- Do NOT use `mutate` on signals, use `update` or `set` instead
113+
114+
### Templates
115+
116+
- Keep templates simple and avoid complex logic
117+
- Use native control flow (`@if`, `@for`, `@switch`) instead of `*ngIf`, `*ngFor`, `*ngSwitch`
118+
- Use the async pipe to handle observables
119+
- Use built in pipes and import pipes when being used in a template, learn more https://angular.dev/guide/templates/pipes#
120+
121+
### Services
122+
123+
- Design services around a single responsibility
124+
- Use the `providedIn: 'root'` option for singleton services
125+
- Use the `inject()` function instead of constructor injection

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ Live Demo with all current modules at https://fullstack-devops.github.io/ngx-mat
4141
- [Theme Switcher](https://github.com/fullstack-devops/ngx-mat-components/blob/main/docs/fs-theme-switcher.md)
4242
- [Calendar](https://github.com/fullstack-devops/ngx-mat-components/blob/main/docs/fs-calendar.md)
4343

44-
> Note: Sometimes I cannot document everything in the `docs/`, so please check the `workspace application` and source code for more information. Or sumbit an [Issue](https://github.com/fullstack-devops/ngx-mat-components/issues)
44+
> Note: Sometimes I cannot document everything in the `docs/`, so please check the `workspace application` and source code for more information. Or sumbit an [Issue](https://github.com/fullstack-devops/ngx-mat-components/issues)

angular.json

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prefix": "lib",
1111
"architect": {
1212
"build": {
13-
"builder": "@angular-devkit/build-angular:ng-packagr",
13+
"builder": "@angular/build:ng-packagr",
1414
"options": {
1515
"tsConfig": "projects/ngx-mat-components/tsconfig.lib.json",
1616
"project": "projects/ngx-mat-components/ng-package.json"
@@ -26,7 +26,7 @@
2626
"defaultConfiguration": "production"
2727
},
2828
"test": {
29-
"builder": "@angular-devkit/build-angular:karma",
29+
"builder": "@angular/build:karma",
3030
"options": {
3131
"main": "projects/ngx-mat-components/src/test.ts",
3232
"tsConfig": "projects/ngx-mat-components/tsconfig.spec.json",
@@ -50,7 +50,7 @@
5050
"prefix": "app",
5151
"architect": {
5252
"build": {
53-
"builder": "@angular-devkit/build-angular:application",
53+
"builder": "@angular/build:application",
5454
"options": {
5555
"outputPath": {
5656
"base": "dist/lib-workspace"
@@ -96,7 +96,7 @@
9696
"defaultConfiguration": "production"
9797
},
9898
"serve": {
99-
"builder": "@angular-devkit/build-angular:dev-server",
99+
"builder": "@angular/build:dev-server",
100100
"configurations": {
101101
"production": {
102102
"buildTarget": "lib-workspace:build:production"
@@ -108,13 +108,13 @@
108108
"defaultConfiguration": "development"
109109
},
110110
"extract-i18n": {
111-
"builder": "@angular-devkit/build-angular:extract-i18n",
111+
"builder": "@angular/build:extract-i18n",
112112
"options": {
113113
"buildTarget": "lib-workspace:build"
114114
}
115115
},
116116
"test": {
117-
"builder": "@angular-devkit/build-angular:karma",
117+
"builder": "@angular/build:karma",
118118
"options": {
119119
"main": "projects/lib-workspace/src/test.ts",
120120
"polyfills": "projects/lib-workspace/src/polyfills.ts",
@@ -138,6 +138,30 @@
138138
},
139139
"@angular-eslint/schematics:library": {
140140
"setParserOptionsProject": true
141+
},
142+
"@schematics/angular:component": {
143+
"type": "component"
144+
},
145+
"@schematics/angular:directive": {
146+
"type": "directive"
147+
},
148+
"@schematics/angular:service": {
149+
"type": "service"
150+
},
151+
"@schematics/angular:guard": {
152+
"typeSeparator": "."
153+
},
154+
"@schematics/angular:interceptor": {
155+
"typeSeparator": "."
156+
},
157+
"@schematics/angular:module": {
158+
"typeSeparator": "."
159+
},
160+
"@schematics/angular:pipe": {
161+
"typeSeparator": "."
162+
},
163+
"@schematics/angular:resolver": {
164+
"typeSeparator": "."
141165
}
142166
}
143167
}

0 commit comments

Comments
 (0)