angular-best-practices by boise-state-development/agentcore-public-stack
npx skills add https://github.com/boise-state-development/agentcore-public-stack --skill angular-best-practicesany;当类型不确定时,使用 unknownstandalone: true — 在 v20+ 中这是默认值)changeDetection: ChangeDetectionStrategy.OnPushinput() 和 output() 函数,而非装饰器computed() 处理派生状态广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
class 绑定而非 ngClassstyle 绑定而非 ngStyle@HostBinding/@HostListener — 请改用装饰器中的 host 对象computed() 处理派生状态mutate — 请改用 update 或 set有关复杂的派生状态模式,请参阅 references/signal-patterns.md。
使用 resource() 配合 signals 进行异步数据获取:
const userResource = resource({
params: () => ({ id: userId() }),
loader: ({ params, abortSignal }) => fetch(`/api/users/${params.id}`, { signal: abortSignal }),
});
const userName = computed(() => userResource.hasValue() ? userResource.value().name : undefined);
关键的 resource 模式:
params 返回 undefined → loader 不会运行,状态变为 'idle'abortSignal 取消正在进行的请求value() 之前检查 hasValue() 以处理加载/错误状态'idle'、'loading'、'reloading'、'resolved'、'error'、'local'@if、@for、@switch(不要使用 *ngIf、*ngFor、*ngSwitch)new Date() 这样的全局变量可用providedIn: 'root'inject() 函数而非构造函数注入@Injectable({ providedIn: 'root' })
export class UserService {
private readonly http = inject(HttpClient);
}
export const routes: Routes = [
{
path: 'admin',
loadComponent: () => import('./admin/admin.page').then(m => m.AdminPage),
},
];
file-name.page.ts、file-name.page.html、file-name.page.cssfile-name.component.tsfile-name.service.tsimport { NgIcon, provideIcons } from '@ng-icons/core';
import { heroSparkles, heroTrash } from '@ng-icons/heroicons/outline';
@Component({
selector: 'app-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIcon],
providers: [provideIcons({ heroSparkles, heroTrash })],
template: `<ng-icon name="heroSparkles" />`,
})
export class ExampleComponent {}
NgOptimizedImageNgOptimizedImage 不适用于内联的 base64 图像每周安装量
515
代码仓库
GitHub 星标数
5
首次出现
2026 年 1 月 25 日
安全审计
安装于
codex466
opencode464
gemini-cli455
github-copilot451
kimi-cli429
amp428
any; use unknown when type is uncertainstandalone: true — it's the default in v20+)changeDetection: ChangeDetectionStrategy.OnPushinput() and output() functions instead of decoratorscomputed() for derived stateclass bindings instead of ngClassstyle bindings instead of ngStyle@HostBinding/@HostListener — use the host object in the decorator insteadcomputed() for derived statemutate on signals — use update or set insteadFor complex derived state patterns, see references/signal-patterns.md.
Use resource() for async data fetching with signals:
const userResource = resource({
params: () => ({ id: userId() }),
loader: ({ params, abortSignal }) => fetch(`/api/users/${params.id}`, { signal: abortSignal }),
});
const userName = computed(() => userResource.hasValue() ? userResource.value().name : undefined);
Key resource patterns:
params returns undefined → loader doesn't run, status becomes 'idle'abortSignal to cancel in-flight requestshasValue() before accessing value() to handle loading/error states'idle', 'loading', 'reloading', 'resolved', 'error', @if, @for, @switch (NOT *ngIf, *ngFor, *ngSwitch)new Date() are availableSingle responsibility per service
Use providedIn: 'root' for singletons
Use inject() function instead of constructor injection
@Injectable({ providedIn: 'root' }) export class UserService { private readonly http = inject(HttpClient); }
Implement lazy loading for feature routes:
export const routes: Routes = [ { path: 'admin', loadComponent: () => import('./admin/admin.page').then(m => m.AdminPage), }, ];
file-name.page.ts, file-name.page.html, file-name.page.cssfile-name.component.tsfile-name.service.tsimport { NgIcon, provideIcons } from '@ng-icons/core';
import { heroSparkles, heroTrash } from '@ng-icons/heroicons/outline';
@Component({
selector: 'app-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIcon],
providers: [provideIcons({ heroSparkles, heroTrash })],
template: `<ng-icon name="heroSparkles" />`,
})
export class ExampleComponent {}
NgOptimizedImage for all static imagesNgOptimizedImage does NOT work for inline base64 imagesWeekly Installs
515
Repository
GitHub Stars
5
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex466
opencode464
gemini-cli455
github-copilot451
kimi-cli429
amp428
Vue.js测试最佳实践:Vue 3组件、组合式函数、Pinia与异步测试完整指南
3,700 周安装
FlowStudio MCP 构建部署 Power Automate 云流指南 | 自动化流程开发
530 周安装
mcp2cli:无需代码,将MCP/OpenAPI/GraphQL实时转换为命令行工具
530 周安装
交互式作品集设计指南:30秒吸引招聘者,提升作品集转化率与个人品牌
530 周安装
每日销售简报AI工具 - 自动生成优先级行动计划,整合日历、CRM和邮件数据
531 周安装
生产排程实战指南:离散制造工厂的有限产能排程、换线优化与瓶颈管理
531 周安装
Angular 21 最佳实践指南:TypeScript、Signals、组件与性能优化
531 周安装
'local'