私は、componentC
の内容が、componentB
のように現れ、そのコンストラクタでDI307を得た3つの成分を持っています。DIおよびtransclusion
@Component({
selector: 'componentA',
template: `
<componentB>
<componentC></componentB>
<ng-content></ng-content>
</componentB>`
....
export class ComponentC {
constructor(private cmpB: ComponentB)
今私は別のコンポーネントからcomponentA
を使用して、私はcomponentA
のテンプレートに入れ<ng-content>
を経由して、それに追加componentC
Sを供給するためにトランスクルーを使用したい:
<componentA>
<componentC></componentC>
</componentA>
これはNo provider for ComponentB
をトリガします。 <ng-content>
を使用して、コンテンツを<componentB>
の内部に表示するようにしました。DIは挿入ポイントの親であるComponentB
オブジェクトを見つけることができるはずです。
このシナリオは可能ですか? Angularは私の余分なComponentC
をターゲットの場所に直接作成するか、最初にマークアップがそれを移動する場所ですか?これを行うようにプロバイダを設定する方法はありますか?
コンポーネントの階層を変更するのではなく、DOMの情報を移動するだけの良い点です。 テンプレートとコンポーネントファクトリを使用してコンテンツを 'componentB'の子としてインスタンス化する別のソリューションがありますか? – achimha