angular-pipes について
テンプレート内の値を変換・整形する Angular 開発者向けのリファレンススキルです。組み込みおよびカスタムパイプ、非同期データ、純粋性や新しい API の指針を説明します。
主な機能
- 01テンプレート内の値の変換
- 02引数付き・連結パイプ
- 03Observable 用の AsyncPipe
- 04スタンドアロン・シグナル対応パイプ
- 05inject() による依存性注入
活用シーン
- 01テンプレート内で値を整形
- 02テンプレートに Observable のデータを表示
- 03オブジェクトの反復処理や JSON の確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ oguzhan18/ angular-ecosystem-skills --skill angular-pipesインストール後、Claude Code で/angular-pipesを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/discussions/_INDEX.mdreferences/docs/_INDEX.mdreferences/issues/_INDEX.mdreferences/releases/_INDEX.md詳細
Angular パイプ
バージョン: Angular 21(2025) タグ: パイプ、変換、フォーマット、非同期
API の変更点
このセクションでは、最近のバージョン固有の API の変更点について説明します。
-
新機能:スタンドアロンパイプ — すべてのパイプをスタンドアロンにできます
-
新機能:シグナルベースのパイプ — パイプでシグナルを使用できます
-
新機能:パイプ内の inject() — パイプで関数型 DI を使用できます
-
非推奨:インピュアパイプ — パフォーマンス上の理由から避け、ピュアパイプを使用してください
ベストプラクティス
- ステートレスな変換にはピュアパイプを使用する
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'capitalize',
standalone: true
})
export class CapitalizePipe implements PipeTransform {
transform(value: string): string {
if (!value) return '';
return value.charAt(0).toUpperCase() + value.slice(1);
}
}
- テンプレート内でパイプを使用する
@Component({
template: `
<p>{{ name | capitalize }}</p>
<p>{{ price | currency:'USD' }}</p>
<p>{{ items | json }}</p>
`
})
export class MyComponent {}
- パラメーターを指定してパイプを使用する
@Pipe({ name: 'slice' })
export class SlicePipe implements PipeTransform {
transform(value: string, start: number, end?: number): string {
return value.slice(start, end);
}
}
// Usage: {{ text | slice:0:10 }}
- Observable には async パイプを使用する
@Component({
template: `
@if (user$ | async; as user) {
<p>{{ user.name }}</p>
}
`
})
export class UserComponent {
user$ = this.userService.getUser();
}
- 必要な場合に限りインピュアパイプを使用する
@Pipe({
name: 'myPipe',
pure: false // Impure - runs on every change detection
})
export class ImpurePipe implements PipeTransform {}
- オブジェクトの反復処理には KeyValue パイプを使用する
@Component({
template: `
@for (item of object | keyvalue; track item.key) {
{{ item.key }}: {{ item.value }}
}
`
})
export class MyComponent {
object = { a: 1, b: 2 };
}
- デバッグには Json パイプを使用する
@Component({
template: `
<pre>{{ object | json }}</pre>
`
})
export class DebugComponent {}
- パイプを連結する
@Component({
template: `
{{ name | uppercase | slice:0:5 }}
`
})
export class ChainedPipeComponent {}
- インポートではスタンドアロンパイプを使用する
@Component({
standalone: true,
imports: [DatePipe, CurrencyPipe, CapitalizePipe],
template: `{{ date | date }}`
})
export class MyComponent {}
- パイプ内で inject() を使用する
@Pipe({ name: 'translate', standalone: true })
export class TranslatePipe implements PipeTransform {
private service = inject(TranslateService);
transform(key: string): string {
return this.service.get(key);
}
}
コメント
Markdown 対応