发布时间:2026/7/24 22:10:01
Angular开发指南_angular-developer 以下为本文档的中文说明angular-developer 是 Angular 官方团队提供的 Angular 代码生成与架构指导技能为 Angular 开发者提供了全面的最佳实践参考。该技能涵盖了 Angular 开发的各个关键领域信号Signals响应式编程包括 linkedSignal 和 resource 等新 API 的正确使用表单处理涵盖模板驱动表单和响应式表单的最佳实践依赖注入包括 provide 函数、注入上下文和层级注入器路由配置包括懒加载、路由守卫和路由解析器服务端渲染SSR的支持无障碍性ARIA的实践指南动画系统的使用组件样式方案包括组件样式封装和 Tailwind CSS 的集成自动化测试包括单元测试和端到端测试的策略以及 Angular CLI 工具链的高效使用。使用场景包括新建 Angular 项目时的架构决策、为现有项目添加新组件或服务、优化应用性能、重构遗留代码、以及解决在开发过程中遇到的具体技术问题。核心原则是在给出任何建议之前先分析项目的 Angular 版本——不同版本之间的最佳实践和可用特性差异很大例如 Angular 17 引入的信号系统在 Angular 16 中并不存在。每当生成代码后技能要求运行 ng build 确保没有构建错误这体现了质量至上的工程理念。该技能遵循 Angular 官方风格指南确保生成的代码在可维护性和性能方面达到生产级标准。Angular Developer GuidelinesAlways analyze the project’s Angular version before providing guidance, as best practices and available features can vary significantly between versions. If creating a new project with Angular CLI, do not specify a version unless prompted by the user.When generating code, follow Angular’s style guide and best practices for maintainability and performance. Use the Angular CLI for scaffolding components, services, directives, pipes, and routes to ensure consistency.Once you finish generating code, runng buildto ensure there are no build errors. If there are errors, analyze the error messages and fix them before proceeding. Do not skip this step, as it is critical for ensuring the generated code is correct and functional.Creating New ProjectsIf no guidelines are provided by the user, here are same default rules to follow when creating a new Angular project:Use the latest stable version of Angular unless the user specifies otherwise.Use Signals Forms for form management in new projects (available in Angular v21 and newer) Find out more.Execution Rules forng new:When asked to create a new Angular project, you must determine the correct execution command by following these strict steps:Step 1: Check for an explicit user version.IFthe user requests a specific version (e.g., Angular 15), bypass local installations and strictly usenpx.Command:npx angular/clirequested_version new project-nameStep 2: Check for an existing Angular installation.IFno specific version is requested, runng versionin the terminal to check if the Angular CLI is already installed on the system.IFthe command succeeds and returns an installed version, use the local/global installation directly.Command:ng new project-nameStep 3: Fallback to Latest.IFno specific version is requested AND theng versioncommand fails (indicating no Angular installation exists), you must usenpxto fetch the latest version.Command:npx angular/clilatest new project-nameComponentsWhen working with Angular components, consult the following references based on the task:Fundamentals: Anatomy, metadata, core concepts, and template control flow (if, for, switch). Read components.mdInputs: Signal-based inputs, transforms, and model inputs. Read inputs.mdOutputs: Signal-based outputs and custom event best practices. Read outputs.mdHost Elements: Host bindings and attribute injection. Read host-elements.mdIf you require deeper documentation not found in the references above, read the documentation athttps://angular.dev/guide/components.Reactivity and Data ManagementWhen managing state and data reactivity, use Angular Signals and consult the following references:Signals Overview: Core signal concepts (signal,computed), reactive contexts, anduntracked. Read signals-overview.mdDependent State (linkedSignal): Creating writable state linked to source signals. Read linked-signal.mdAsync Reactivity (resource): Fetching asynchronous data directly into signal state. Read resource.mdSide Effects (effect): Logging, third-party DOM manipulation (afterRenderEffect), and when NOT to use effects. Read effects.mdFormsIn most cases for new apps,prefer signal forms. When making a forms decision, analyze the project and consider the following guidelines:if the application is using v21 or newer and this is a new form,prefer signal forms.-For older applications or when working with existing forms, use the appropriate form type that matches the applications current form strategy.Signal Forms: Use signals for form state management. Read [signal-forms.md](references/signal-forms.md)Template-driven forms: Use for simple forms. Read template-driven-forms.mdReactive forms: Use for complex forms. Read reactive-forms.mdDependency InjectionWhen implementing dependency injection in Angular, follow these guidelines:Fundamentals: Overview of Dependency Injection, services, and theinject()function. Read di-fundamentals.mdCreating and Using Services: Creating services, theprovidedIn: rootoption, and injecting into components or other services. Read creating-services.mdDefining Dependency Providers: Automatic vs manual provision,InjectionToken,useClass,useValue,useFactory, and scopes. Read defining-providers.mdInjection Context: Whereinject()is allowed,runInInjectionContext, andassertInInjectionContext. Read injection-context.mdHierarchical Injectors: TheEnvironmentInjectorvsElementInjector, resolution rules, modifiers (optional,skipSelf), andprovidersvsviewProviders. Read hierarchical-injectors.mdAngular AriaWhen building accessible custom components for any of the following patterns: Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid, consult the following reference:Angular Aria Components: Building headless, accessible components (Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid) and styling ARIA attributes. Read angular-aria.mdRoutingWhen implementing navigation in Angular, consult the following references:Define Routes: URL paths, static vs dynamic segments, wildcards, and redirects. Read define-routes.mdRoute Loading Strategies: Eager vs lazy loading, and context-aware loading. Read loading-strategies.mdShow Routes with Outlets: Usingrouter-outlet, nested outlets, and named outlets. Read show-routes-with-outlets.mdNavigate to Routes: Declarative navigation withRouterLinkand programmatic navigation withRouter. Read navigate-to-routes.mdControl Route Access with Guards: ImplementingCanActivate,CanMatch, and other guards for security. Read route-guards.mdData Resolvers: Pre-fetching data before route activation withResolveFn. Read>Styling and AnimationsWhen implementing styling and animations in Angular, consult the following references:Using Tailwind CSS with Angular: Integrating Tailwind CSS into Angular projects. Read tailwind-css.mdAngular Animations: Using native CSS (recommended) or the legacy DSL for dynamic effects. Read angular-animations.mdStyling components: Best practices for component styles and encapsulation. Read component-styling.mdTestingWhen writing or updating tests, consult the following references based on the task:Fundamentals: Best practices for unit testing (Vitest), async patterns, andTestBed. Read [testing-fundamentals.md](references/testing-fundamentals.md)Component Harnesses: Standard patterns for robust component interaction. Read component-harnesses.mdRouter Testing: UsingRouterTestingHarnessfor reliable navigation tests. Read router-testing.mdEnd-to-End (E2E) Testing: Best practices for E2E tests with Cypress. Read e2e-testing.mdToolingWhen working with Angular tooling, consult the following references:Angular CLI: Creating applications, generating code (components, routes, services), serving, and building. Read cli.mdCode Modernization: Automatically refactoring to modern standards using migrations. Read migrations.mdAngular MCP Server: Available tools, configuration, and experimental features. Read mcp.md3e:[“ , ,,L41”,null,{“content”:“$42”,“frontMatter”:{“name”:“angular-developer”,“description”:“Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.”,“license”:“MIT”,“metadata”:{“author”:“Copyright 2026 Google LLC”,“version”:“1.0”}}}]3f:[“KaTeX parse error: Expected }, got EOF at end of input: …,children:[[”,“div”,null,{“className”:“flex items-center justify-between border-b border-border bg-muted/30 px-4 py-2.5”,“children”:[[“KaTeX parse error: Expected }, got EOF at end of input: …,children:[”,“span”,null,{“className”:“truncate text-xs font-medium text-muted-foreground”,“children”:“同仓库更多 Skills”}]}],[“KaTeX parse error: Expected EOF, got } at position 88: …ldren:同仓库}]]}̲],[”,“div”,null,{“className”:“p-4 sm:p-5”,“children”:[[“ , h 2 , n u l l , i d : r e l a t e d − s k i l l s − h e a d i n g , c l a s s N a m e : t e x t − 2 x l f o n t − s e m i b o l d t r a c k i n g − n o r m a l t e x t − f o r e g r o u n d , c h i l d r e n : 同仓库更多 S k i l l s ] , [ ,h2,null,{id:related-skills-heading,className:text-2xl font-semibold tracking-normal text-foreground,children:同仓库更多 Skills}],[,h2,null,id:related−skills−heading,className:text−2xlfont−semiboldtracking−normaltext−foreground,children:同仓库更多Skills],[”,“div”,null,{“className”:“mt-4 grid gap-3 sm:grid-cols-2”,“children”:[“L 43 , L43,L43,L44”,“$L45”]}]]}]]}]46:I[206516,[“/_next/static/chunks/051aanbhrv4br.js”,“/_next/static/chunks/0mizr60h7ayzt.js”,“/_next/static/chunks/0v9lm1dmbdoo-.js”,“/_next/static/chunks/0rxr1j1j3j-.r.js”,“/_next/static/chunks/02ftybezfvqjd.js”,“/_next/static/chunks/0.v9ksvnnj8ia.js”,“/_next/static/chunks/0bn6id96nx3k.js,“/_next/static/chunks/13ybnhn37c.tc.js”,“/_next/static/chunks/0_fnrdtruz8uf.js”,“/_next/static/chunks/0r6l15utt1mwb.js”,“/_next/static/chunks/0dm9a5into854.js”,/_next/static/chunks/07k6hqoibtcn.js”,“/next/static/chunks/0b4cao.4y…j.js”,“/_next/static/chunks/02i-n28z7kjd0.js”],“default”]

相关新闻

2026/7/24 22:05:01

天线原理-1.引论

天线的概念 天线是辐射或接受电磁波的装置 天线 antenna 触须 天线 aerial 空中的线 天线是如何发明的 麦克斯韦提出电磁场方程组,预示电磁波的存在1886年,赫兹采用电火花间隙发射机和环形天线,验证了电磁波的存在。1895年,马可…

2026/7/24 23:35:06

MiGPT终极指南:3步解锁小爱音箱的AI智能管家潜能

MiGPT终极指南:3步解锁小爱音箱的AI智能管家潜能 【免费下载链接】mi-gpt 🏠 将小爱音箱接入 ChatGPT 和豆包,改造成你的专属语音助手。 项目地址: https://gitcode.com/GitHub_Trending/mi/mi-gpt 在智能家居时代,你的小爱…

2026/7/24 23:35:06

剑网3智能助手:5分钟打造你的专属游戏伴侣

剑网3智能助手:5分钟打造你的专属游戏伴侣 【免费下载链接】mini_jx3_bot 女生自用剑网三机器人 项目地址: https://gitcode.com/gh_mirrors/mi/mini_jx3_bot 在剑网3的武侠世界中,你是否曾为查询装备属性、追踪奇遇记录、监控金价波动而烦恼&…

2026/7/24 23:35:06

基于生物重构与量子信息还原的人类个体复刻与意识复活完整机制研究「探索无止境,敬畏生命本源,诸神归位,众生俯首」最终落地20-50年

摘要传统生命科学认为:机体死亡代表个体意识不可逆湮灭,生命进程彻底终止。该结论局限于经典生物学与经典力学框架,忽略了量子信息守恒、全脑连接组学、表观遗传印记留存、原子级结构可重构等前沿跨学科理论。本文基于分子生物学、神经连接组…

2026/7/24 23:35:06

Kimi LeetCode 3681. 子序列最大 XOR 值 Python3实现

LeetCode 3681. 子序列最大 XOR 值 — Python3 实现核心思路这道题的关键在于一个巧妙的转化:题目要求选择两个允许重叠的子序列,设它们的 XOR 分别为 X 和 Y,求 X XOR Y 的最大值。对于每个元素 nums[i],它在 X XOR Y 中的贡献取…

2026/7/24 23:30:05

嵌入式从0到精通——Linux操作命令篇

总目录Linux基础C语言数据结构Linux应用软件开发单片机硬件开发(ARM)驱动开发一、Linux基础Linux:操作系统、内核1. 虚拟机快捷方式CtrlAlt T 打开终端CtrlShift ‘’ 放大终端Ctrl ‘-’ 缩小终端2. Linux相关命令命令行格式:linuxubuntu:~/20250905…

2026/7/23 12:54:51

Unity与Python本地通信:基于Flask的跨语言数据交换实战

1. 项目概述:为什么我们需要一个本地通信服务器?在游戏开发、数字孪生、仿真训练等众多领域,Unity作为强大的实时3D内容创作平台,其核心逻辑通常由C#驱动。然而,当我们需要进行复杂的数据分析、机器学习推理、科学计算…

2026/7/24 0:03:10

不同品牌斜齿行星减速机如何替换?以PX与PAG系列为例

不同品牌斜齿行星减速机如何替换?以 PX 与 PAG 系列为例 一、系列对应不等于型号直接互换 PX 与 PAG 都属于斜齿、方法兰、输出轴式精密行星减速机,结构形式和应用方向具有对应关系。 原设备使用PX系列时,可以优先从PAG系列中寻找替换型号。但…

2026/7/24 0:03:10

jdk8 把list 扁平化成String 多个以逗号分隔

在 JDK 8 中&#xff0c;将 List 扁平化为以逗号分隔的 String&#xff0c;有几种非常简洁且高效的方法。&#x1f680; 推荐方案&#xff1a;使用 Collectors.joining()这是最标准的 Java 8 写法&#xff0c;适用于 List<String>。javaimport java.util.stream.Collecto…

2026/7/24 0:03:10

java 两个 long id 怎么合并成一个long id 并且不重复

“把两个 Long ID 合并成一个唯一的 Long ID&#xff0c;且保证不重复”这个需求&#xff0c;在 Java 里直接做数学上的“完美合并”是不可能的。因为两个 Long&#xff08;各 64 位&#xff09;要合并成一个 Long&#xff08;64 位&#xff09;&#xff0c;在信息论上是有损压…

2026/7/23 23:42:43

3个高效策略:快速掌握Axure中文界面配置

3个高效策略&#xff1a;快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…