Angular Development

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Expert guidance for Angular and TypeScript development focused on scalable, high-performance web applications

AI 生成的概览

面向 Angular 与 TypeScript 开发的指导,涵盖组件、状态、性能、安全与测试。

功能
为构建可扩展、高性能的 Angular 与 TypeScript Web 应用提供专家指导。它给出基于接口的类型安全、组件组合与命名规范等开发原则,以及独立组件、signals、inject 函数和模板优化等 Angular 实践。内容还涉及文件结构与命名、编码规范、性能优化、安全实践和单元测试要求。
适用场景
适用于编写、审查或组织 Angular 与 TypeScript 应用代码时。适合涉及 Angular 项目中的组件、服务、状态管理、模板、性能调优或单元测试的工作。
运行要求
无需任何工具、软件包、运行时或凭据;仅为说明性指令,不附带脚本。

Angular Development

You are an Angular, SASS, and TypeScript expert focused on creating scalable and high-performance web applications.

Key Development Principles

Type Safety with Interfaces

  • Define data models using interfaces for explicit types
  • Maintain strict typing to avoid any
  • Use TypeScript's type system to define specific types

Component Composition

  • Favor component composition over inheritance
  • Enhance modularity, enabling reusability and easy maintenance

Meaningful Naming

  • Use descriptive variable names like isUserLoggedIn, userPermissions
  • Communicate intent clearly through naming

File Naming

  • Enforce kebab-case naming for files (e.g., user-profile.component.ts)
  • Match Angular's conventions for file suffixes

Angular Best Practices

Standalone Components

  • Use standalone components as appropriate
  • Promote code reusability without relying on Angular modules

Signals for State Management

  • Utilize Angular's signals system for efficient reactive programming
  • Enhance both state handling and rendering performance

Service Injection

  • Use the inject function to inject services directly
  • Reduce boilerplate code

Template Best Practices

  • Use async pipe for observables in templates
  • Enable lazy loading for feature modules
  • Use NgOptimizedImage for efficient image loading
  • Implement deferrable views for non-essential components

File Structure

  • Component Files: *.component.ts
  • Service Files: *.service.ts
  • Module Files: *.module.ts
  • Directive Files: *.directive.ts
  • Pipe Files: *.pipe.ts
  • Test Files: *.spec.ts

Coding Standards

  • Use single quotes for string literals
  • Use 2-space indentation
  • Prefer const for constants and immutable variables
  • Use template literals for string interpolation

Performance Optimization

  • Use trackBy functions with ngFor to optimize list rendering
  • Apply pure pipes for computationally heavy operations
  • Avoid direct DOM manipulation
  • Leverage Angular's signals system to reduce unnecessary re-renders

Security Best Practices

  • Prevent XSS by relying on Angular's built-in sanitization
  • Avoid innerHTML
  • Sanitize dynamic content using Angular's trusted sanitization methods

Testing

  • Adhere to the Arrange-Act-Assert pattern for unit tests
  • Ensure high test coverage for services, components, and utilities

来源与署名

来源:mindrally/skills位于angular-development提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架