+
+ `
+})
+export class DynamicCard {
+ private vcr = inject(ViewContainerRef);
+ cardComponent = CardWrapper;
+
+ private contentTemplate = viewChild>('contentTemplate');
+
+ cardContent = computed(() => {
+ const template = this.contentTemplate();
+ if (!template) return [];
+ // Returns an array of projection slots. Each element represents one slot.
+ // CardWrapper has one , so we return an array with one element.
+ return [this.vcr.createEmbeddedView(template).rootNodes];
+ });
+}
+```
+
+### Providing injectors
+
+You can provide a custom injector to the dynamically created component using `ngComponentOutletInjector`. This is useful for providing component-specific services or configuration.
+
+```angular-ts
+export const THEME_DATA = new InjectionToken('THEME_DATA', {
+ factory: () => 'light',
+});
+
+@Component({
+ selector: 'themed-panel',
+ template: `
`
+})
+export class Counter {
+ count = signal(0);
+ increment() {
+ this.count.update(c => c + 1);
+ }
+}
+
+@Component({
+ imports: [NgComponentOutlet],
+ template: `
+
+
+
+ `
+})
+export class CounterHost {
+ counterComponent = Counter;
+}
+```
+
+NOTE: The `componentInstance` property is `null` before the component is rendered.
+
See the [NgComponentOutlet API reference](api/common/NgComponentOutlet) for more information on the
directive's capabilities.