MCPcopy
hub / github.com/CopilotKit/CopilotKit / renderSlot

Function renderSlot

packages/angular/src/lib/slots/slot.utils.ts:41–84  ·  view source on GitHub ↗
(
  viewContainer: ViewContainerRef,
  options: RenderSlotOptions<T>,
)

Source from the content-addressed store, hash-verified

39 * ```
40 */
41export function renderSlot<T = any>(
42 viewContainer: ViewContainerRef,
43 options: RenderSlotOptions<T>,
44): ComponentRef<T> | EmbeddedViewRef<T> | null {
45 const { slot, defaultComponent, props, injector, outputs } = options;
46
47 viewContainer.clear();
48
49 const effectiveSlot = slot ?? defaultComponent;
50 const effectiveInjector = injector ?? viewContainer.injector;
51
52 if (effectiveSlot instanceof TemplateRef) {
53 // TemplateRef: render template
54 return viewContainer.createEmbeddedView(effectiveSlot, {
55 $implicit: props ?? {},
56 props: props ?? {},
57 } as any);
58 } else if (isComponentType(effectiveSlot)) {
59 // Component type - wrap in try/catch for safety
60 try {
61 return createComponent(
62 viewContainer,
63 effectiveSlot as Type<T>,
64 props,
65 effectiveInjector,
66 outputs,
67 );
68 } catch (error) {
69 console.warn("Failed to create component:", effectiveSlot, error);
70 // Fall through to default component
71 }
72 }
73
74 // Default: render default component if provided
75 return defaultComponent
76 ? createComponent(
77 viewContainer,
78 defaultComponent,
79 props,
80 effectiveInjector,
81 outputs,
82 )
83 : null;
84}
85
86/**
87 * Creates a component and applies properties.

Callers 3

renderSlotMethod · 0.90
slot.utils.spec.tsFile · 0.90
createSlotRendererFunction · 0.70

Calls 4

isComponentTypeFunction · 0.85
createComponentFunction · 0.85
warnMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…