en un clic
angular-frontend
// Guidelines for creating and configuring Angular projects. Use when creating a new Angular project or when asked to configure an existing one.
// Guidelines for creating and configuring Angular projects. Use when creating a new Angular project or when asked to configure an existing one.
| name | angular-frontend |
| description | Guidelines for creating and configuring Angular projects. Use when creating a new Angular project or when asked to configure an existing one. |
| metadata | {"author":"Rainer Stropek"} |
If you are creating a new Angular project, read the official angular-new-app skill first.
If you are looking for general information about Angular, read the official angular-developer skill. If it does not contain what you are looking for, search in https://angular.dev/llms.txt.
Add environment-related configuration (ng generate environments)
We do not use Cypress for end-to-end testing. Instead, we use Playwright. Note: The angular-developer skill's e2e-testing reference covers Cypress — ignore it. This project uses Playwright exclusively. See the playwright-cli skill.
For repeatable Playwright tests, install the Playwright package in the Angular app:
e2e folder.Add a JS script build/set-env.js that updates the environment.apiBaseUrl environment setting according to the Aspire environment variables (process.env.services__webapi__https__0 || process.env.services__webapi__http__0). The script must write to both src/environments/environment.ts and src/environments/environment.development.ts. Call this JS script in the package.json start script before starting the Angular development server.
The start script must pass the PORT environment variable to the Angular development server (ng serve --port $PORT), so that it works correctly in the Aspire environment.
Use the Aspire.Hosting.NodeJs NuGet package in the Aspire AppHost to host the Angular application. Use AddNpmApp to add the Angular project to the AppHost (with a reference to the web API).
Configure Playwright to run against the local dev server URL provided by Aspire (read the aspire skill to understand how to start the application and discover service URLs).
When used together with an ASP.NET Core Minimal API web API project, we generate API clients from the Open API specification generated by the web API project. This allows for type-safe API calls in the Angular frontend.
ng-openapi-gen package (dev dependency)generate-web-api script to package.json:
ng-openapi-gen --input <relative-path-to-web-api>/<web-api-project-name>.json --output src/app/apiAlways use the generated API client for API calls, do not call the API directly using HttpClient. This ensures type safety and consistency with the API specification.
We use angular-eslint for linting. It is added via ng add angular-eslint and configured in eslint.config.js (flat config format).
pnpm ng lint (or ng lint) in the Frontend folder.src/app/api/) is excluded from linting via an ignores entry in eslint.config.js.In app.config.ts:
provideZonelessChangeDetection()provideHttpClient(withFetch())provideRouter(routes, withComponentInputBinding())any type; use unknown when type is uncertainstandalone: true inside Angular decorators. It's the default in Angular v20+.@HostBinding and @HostListener decorators. Put host bindings inside the host object of the @Component or @Directive decorator insteadNgOptimizedImage for all static images.
NgOptimizedImage does not work for inline base64 images.input() and output() functions instead of decoratorscomputed() for derived statechangeDetection: ChangeDetectionStrategy.OnPush in @Component decoratorangular-developer skill). For Angular v20 or existing code, prefer Reactive forms over Template-driven ones.ngClass, use class bindings insteadngStyle, use style bindings insteadcomputed() for derived statemutate on signals, use update or set instead@if, @for, @switch) instead of *ngIf, *ngFor, *ngSwitchtoSignal() from @angular/core/rxjs-interop. Use the async pipe only when signal conversion is impractical.new Date()) are available.providedIn: 'root' option for singleton servicesinject() function instead of constructor injection