mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +08:00
Translated 85 skill sub-reference files to achieve full parity with the English source: - skills/angular-developer/references/ — 35 files (all references) - skills/remotion-video-creation/rules/ — 28 files (all rules) - skills/tinystruct-patterns/references/ — 5 files - skills/openclaw-persona-forge/references/ — 6 files - skills/skill-comply/prompts/ — 3 files - skills/lead-intelligence/agents/ — 4 files - skills/brand-voice/references/ — 1 file - skills/frontend-slides/ — 2 files - hooks/memory-persistence/README.md — 1 file English source parity: 0 missing files (excluding rules/zh/, internal docs, and experimental examples absent from zh-CN)
2.7 KiB
2.7 KiB
階層的インジェクター
Angularの依存性注入システムは階層的であり、サービスをアプリケーションの異なるレベルにスコープできます。
インジェクター階層の種類
EnvironmentInjector階層:@Injectable({ providedIn: 'root' })またはブートストラップ時のApplicationConfig.providersで設定されます。これらはグローバルシングルトンです。ElementInjector階層: 各DOM要素で暗黙的に作成されます。@Component()または@Directive()のprovidersまたはviewProviders配列で設定されます。
解決ルール
依存関係が要求されると、Angularは2つのフェーズで解決します:
- リクエスト元のコンポーネント/ディレクティブからルート要素まで、
ElementInjectorツリーを上方向に検索します。 - 見つからない場合、最も近い環境インジェクターからルートまで、
EnvironmentInjectorツリーを検索します。 - それでも見つからない場合、エラーをスローします(オプションとしてマークされている場合を除く)。
解決モディファイアー
inject() のオプションオブジェクトを使用して、Angularが依存関係を検索する方法を変更できます:
optional: 依存関係が見つからない場合、エラーをスローする代わりにnullを返します。self: 現在のElementInjectorのみをチェックします。親ツリーを検索しません。skipSelf: 現在の要素をスキップして、親のElementInjectorから検索を開始します。host: ホストコンポーネントのビュー境界に達したら検索を停止します。
@Component({...})
export class Example {
// 見つからない場合はクラッシュせずnullを返す
optionalService = inject(MyService, { optional: true });
// このコンポーネントのプロバイダーをスキップして親を参照する
parentService = inject(ParentService, { skipSelf: true });
}
providers と viewProviders
コンポーネントレベルでサービスを提供する場合:
providers: サービスはコンポーネント、そのビュー(テンプレート)、およびプロジェクトされたコンテンツ(<ng-content>)で利用可能です。viewProviders: サービスはコンポーネントとそのビューで利用可能ですが、プロジェクトされたコンテンツからは利用できません。コンシューマーから渡されたコンテンツからサービスを分離するために使用します。