1

I want to dynamically create the injector for embeddedView and for that purpose I use Injector.create() method:

const myInjector = Injector.create({
        providers: [
            {
                provide: MyService,
                useFactory: () => new MyService(),
            },
        ],
        parent: this.vcr.injector,
    });

then I create embedded view

const view = this.template.createEmbeddedView(
        null,
        myInjector
    );

the problem is the template components do not get the services of this.vcr.injector but they do get istance of MyService

but when I create the embeddedView like this:

const view = this.template.createEmbeddedView(
            null,
            this.vcr.injector
        );

The this.vcr.injector works and templates get the instances of services but I need the ability to create providers for some templates and for some not.

1
  • please share working example for debugging, also what is wrong with the stackblitz and expected output Commented Oct 23, 2024 at 15:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.