SuperAPI AI 工具集

angular-component

前端与建站

查看项目

更新于 10-16 03:40

技能介绍

用途:按 Angular v20+ 最佳实践创建现代独立组件(standalone component)。组件默认即为独立,无需设置 standalone: true。

主要能力与约定:

  • 组件结构:使用 @Component 装饰器,配合 ChangeDetectionStrategy.OnPush、host 对象、template 与 styles。
  • Signal 输入:input.required() 表示必填,input(默认值) 表示可选,支持 alias 别名与 transform 转换函数(如 booleanAttribute、numberAttribute)。
  • Signal 输出:使用 output() 定义,支持 alias;可通过 outputFromObservable 与 RxJS 互操作,用 emit 发送值。
  • Host 绑定:在 @Component 的 host 对象中声明静态属性、class/style/attr 绑定与事件监听,不使用 @HostBinding、@HostListener。
  • 内容投影:使用 ng-content,支持 select 选择器。
  • 生命周期:可使用 OnInit、OnDestroy,以及 afterNextRender、afterRender 进行 SSR 安全的 DOM 操作。
  • 模板语法:使用原生控制流 @if、@for(含 track、@empty)、@switch,不使用 *ngIf、*ngFor、*ngSwitch。
  • 类与样式绑定:使用 [class.x]、[class]、[style.x]、[style.width.px] 等直接绑定,不使用 ngClass、ngStyle。
  • 图片:静态图片使用 NgOptimizedImage 的 ngSrc、width、height、priority。
  • 无障碍:组件需通过 AXE 检查、符合 WCAG AA,交互元素需具备 ARIA 属性、键盘导航与可见焦点指示。

使用方式:该技能以参考文档形式提供组件模式(如 references/component-patterns.md),供在编写 Angular 组件时遵循上述规范。

适用场景:构建 Angular v20+ 的 UI 组件库或应用界面组件。

限制:资料未提供安装命令、收费、价格、平台支持范围及具体效果说明,暂未提供。