angular-developer by angular/angular
npx skills add https://github.com/angular/angular --skill angular-developer在提供指导前,务必先分析项目的 Angular 版本,因为不同版本间的最佳实践和可用功能可能存在显著差异。如果使用 Angular CLI 创建新项目,除非用户明确要求,否则不要指定版本。
生成代码时,请遵循 Angular 的风格指南和最佳实践,以确保代码的可维护性和性能。使用 Angular CLI 来搭建组件、服务、指令、管道和路由的脚手架,以确保一致性。
完成代码生成后,运行 ng build 以确保没有构建错误。如果存在错误,请分析错误信息并在继续之前修复它们。不要跳过此步骤,这对于确保生成的代码正确且功能正常至关重要。
如果用户未提供指导,以下是创建新 Angular 项目时遵循的一些默认规则:
ng new 的执行规则: 当被要求创建新的 Angular 项目时,您必须遵循以下严格步骤来确定正确的执行命令:
步骤 1:检查用户是否明确指定了版本。
npx。npx @angular/cli@<requested_version> ng new <project-name>广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
步骤 2:检查是否已安装 Angular。
ng version 以检查系统上是否已安装 Angular CLI。ng new <project-name>步骤 3:回退到最新版本。
ng version 命令失败(表明未安装 Angular),则必须使用 npx 来获取最新版本。npx @angular/cli@latest ng new <project-name>在处理 Angular 组件时,根据任务查阅以下参考资料:
如果您需要上面参考资料中未找到的更深入文档,请阅读 https://angular.dev/guide/components 上的文档。
在管理状态和数据响应式时,请使用 Angular Signals 并查阅以下参考资料:
signal、computed)、响应式上下文和 untracked。阅读 signals-overview.mdlinkedSignal):创建与源信号关联的可写状态。阅读 linked-signal.mdresource):将异步数据直接获取到信号状态中。阅读 resource.mdeffect):日志记录、第三方 DOM 操作(afterRenderEffect)以及何时不应使用 effects。阅读 effects.md对于大多数新应用,首选信号表单。在做出表单决策时,请分析项目并考虑以下准则:
如果应用程序使用的是 v21 或更高版本,并且这是一个新表单,首选信号表单。
对于较旧的应用程序或处理现有表单时,请使用与应用程序当前表单策略匹配的适当表单类型。
信号表单:使用 signals 进行表单状态管理。阅读 signal-forms.md
模板驱动表单:用于简单表单。阅读 template-driven-forms.md
响应式表单:用于复杂表单。阅读 reactive-forms.md
在 Angular 中实现依赖注入时,请遵循以下准则:
inject() 函数。阅读 di-fundamentals.mdprovidedIn: 'root' 选项以及注入到组件或其他服务中。阅读 creating-services.mdInjectionToken、useClass、useValue、useFactory 和作用域。阅读 defining-providers.mdinject() 的地方、runInInjectionContext 和 assertInInjectionContext。阅读 injection-context.mdEnvironmentInjector 与 ElementInjector、解析规则、修饰符(optional、skipSelf)以及 providers 与 viewProviders。阅读 hierarchical-injectors.md在为以下任何模式构建可访问的自定义组件时:手风琴、列表框、组合框、菜单、选项卡、工具栏、树、网格,请查阅以下参考资料:
在 Angular 中实现导航时,请查阅以下参考资料:
<router-outlet>、嵌套出口和命名出口。阅读 show-routes-with-outlets.mdRouterLink 进行声明式导航和使用 Router 进行编程式导航。阅读 navigate-to-routes.mdCanActivate、CanMatch 和其他用于安全性的守卫。阅读 route-guards.mdResolveFn 在路由激活前预取数据。阅读 data-resolvers.md如果您需要更深入的文档或更多上下文,请访问 官方 Angular 路由指南。
在 Angular 中实现样式和动画时,请查阅以下参考资料:
在编写或更新测试时,根据任务查阅以下参考资料:
TestBed。阅读 testing-fundamentals.mdRouterTestingHarness 进行可靠的导航测试。阅读 router-testing.md在使用 Angular 工具时,请查阅以下参考资料:
每周安装次数
267
代码仓库
GitHub 星标
100.2K
首次出现
6 天前
安全审计
安装于
github-copilot265
codex265
opencode265
cursor265
kimi-cli264
gemini-cli264
Always 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, run ng build to 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.
If no guidelines are provided by the user, here are same default rules to follow when creating a new Angular project:
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.
npx.npx @angular/cli@<requested_version> ng new <project-name>Step 2: Check for an existing Angular installation.
ng version in the terminal to check if the Angular CLI is already installed on the system.ng new <project-name>Step 3: Fallback to Latest.
ng version command fails (indicating no Angular installation exists), you must use npx to fetch the latest version.npx @angular/cli@latest ng new <project-name>When working with Angular components, consult the following references based on the task:
If you require deeper documentation not found in the references above, read the documentation at https://angular.dev/guide/components.
When managing state and data reactivity, use Angular Signals and consult the following references:
signal, computed), reactive contexts, and untracked. Read signals-overview.mdlinkedSignal): Creating writable state linked to source signals. Read linked-signal.mdresource): Fetching asynchronous data directly into signal state. Read resource.mdeffect): Logging, third-party DOM manipulation (afterRenderEffect), and when NOT to use effects. Read In 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
Template-driven forms : Use for simple forms. Read template-driven-forms.md
Reactive forms : Use for complex forms. Read reactive-forms.md
When implementing dependency injection in Angular, follow these guidelines:
inject() function. Read di-fundamentals.mdprovidedIn: 'root' option, and injecting into components or other services. Read creating-services.mdInjectionToken, useClass, useValue, useFactory, and scopes. Read defining-providers.mdinject() is allowed, , and . Read When building accessible custom components for any of the following patterns: Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid, consult the following reference:
When implementing navigation in Angular, consult the following references:
<router-outlet>, nested outlets, and named outlets. Read show-routes-with-outlets.mdRouterLink and programmatic navigation with Router. Read navigate-to-routes.mdCanActivate, CanMatch, and other guards for security. Read If you require deeper documentation or more context, visit the official Angular Routing guide.
When implementing styling and animations in Angular, consult the following references:
When writing or updating tests, consult the following references based on the task:
TestBed. Read testing-fundamentals.mdRouterTestingHarness for reliable navigation tests. Read router-testing.mdWhen working with Angular tooling, consult the following references:
Weekly Installs
267
Repository
GitHub Stars
100.2K
First Seen
6 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
github-copilot265
codex265
opencode265
cursor265
kimi-cli264
gemini-cli264
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装
runInInjectionContextassertInInjectionContextEnvironmentInjector vs ElementInjector, resolution rules, modifiers (optional, skipSelf), and providers vs viewProviders. Read hierarchical-injectors.mdResolveFn. Read data-resolvers.md