angular-material
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese@angular/material & @angular/cdk
@angular/material & @angular/cdk
Version: 21.0.3 (Feb 2026)
Tags: Material Design, CDK, Components, UI Library
版本: 21.0.3(2026年2月)
标签: Material Design, CDK, Components, UI Library
API Changes
API 变更
This section documents recent version-specific API changes.
-
NEW: Angular Aria — New low-level component library for accessible, headless components that can be styled custom source
-
NEW: CDK overlays now use browser's built-in popovers for improved accessibility source
-
NEW: Material Design system tokens — Use utility classes to apply Material tokens directly in templates source
-
NEW: CDK Drag & Drop improvements — Allow copying items between lists source
-
NEW: Angular v21 — Full support for new Angular features including zoneless change detection
Best Practices
最佳实践
- Use standalone components — Import Material components directly without NgModule
ts
import { Component } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
@Component({
standalone: true,
imports: [MatButtonModule, MatCardModule],
// ...
})
export class ExampleComponent {}-
Use CDK for custom components — Use CDK (Component Dev Kit) for behavior primitives like drag-drop, overlays, menus without Material styling
-
Use CDK Virtual Scroll for large lists — Improve performance withinstead of rendering all items
cdkVirtualScrollViewport
html
<cdk-virtual-scroll-viewport itemSize="50" class="viewport">
<div *cdkVirtualFor="let item of items">{{item.name}}</div>
</cdk-virtual-scroll-viewport>-
Usewith
trackBy— Prevent unnecessary DOM re-rendersngFor -
Customize themes with SCSS — Use Material's theming system for custom colors and typography
-
Use— Improve performance with default change detection strategy
ChangeDetectionStrategy.OnPush -
Follow accessibility guidelines — Use ARIA labels, keyboard navigation, and focus management provided by CDK components
- 使用独立组件 — 无需NgModule即可直接导入Material组件
ts
import { Component } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
@Component({
standalone: true,
imports: [MatButtonModule, MatCardModule],
// ...
})
export class ExampleComponent {}-
自定义组件优先使用CDK — 借助CDK(Component Dev Kit)提供的行为原语实现拖拽、浮层、菜单等功能,无需引入Material样式
-
长列表使用CDK虚拟滚动 — 使用代替渲染所有元素,提升性能
cdkVirtualScrollViewport
html
<cdk-virtual-scroll-viewport itemSize="50" class="viewport">
<div *cdkVirtualFor="let item of items">{{item.name}}</div>
</cdk-virtual-scroll-viewport>-
搭配
ngFor使用 — 避免不必要的DOM重渲染trackBy -
使用SCSS自定义主题 — 借助Material的主题系统实现自定义颜色和排版
-
使用— 采用该变更检测策略提升性能
ChangeDetectionStrategy.OnPush -
遵循可访问性规范 — 使用CDK组件提供的ARIA标签、键盘导航和焦点管理能力