Reputation: 2456
I need to call the following code with a new injector created to add providers dynamically:
var componentRef = componentFactory.create(
injector, undefined, `#${this.id}`
);
I can't find an example on the internet on howto create a child injector whose parent is the component injector. Any ideas?
I have tried to inject a ReflectiveInjector
(so i can call resolveAndCreateChild
method) into may component but an exception is raised at runtime saying there is no provider for that class.
Upvotes: 0
Views: 269
Reputation: 993
inject Injector and then
let resolvedProviders = ReflectiveInjector.resolve([new Provider('node', { useValue: node })]);
let child = ReflectiveInjector.fromResolvedProviders(resolvedProviders, this.injector);
Upvotes: 1