* Attaches the user-provided component to the already-created dialog container. * @param componentOrTemplateRef The type of component being loaded into the dialog, * or a TemplateRef to instantiate as the content. * @param dialogRef Reference to the dialog being opened. * @param dial
(
componentOrTemplateRef: ComponentType<C> | TemplateRef<C>,
dialogRef: DialogRef<R, C>,
dialogContainer: DialogContainer,
config: DialogConfig<D, DialogRef<R, C>>,
)
| 278 | * @param config Configuration used to open the dialog. |
| 279 | */ |
| 280 | private _attachDialogContent<R, D, C>( |
| 281 | componentOrTemplateRef: ComponentType<C> | TemplateRef<C>, |
| 282 | dialogRef: DialogRef<R, C>, |
| 283 | dialogContainer: DialogContainer, |
| 284 | config: DialogConfig<D, DialogRef<R, C>>, |
| 285 | ) { |
| 286 | if (componentOrTemplateRef instanceof TemplateRef) { |
| 287 | const injector = this._createInjector(config, dialogRef, dialogContainer, undefined); |
| 288 | let context: any = {$implicit: config.data, dialogRef}; |
| 289 | |
| 290 | if (config.templateContext) { |
| 291 | context = { |
| 292 | ...context, |
| 293 | ...(typeof config.templateContext === 'function' |
| 294 | ? config.templateContext() |
| 295 | : config.templateContext), |
| 296 | }; |
| 297 | } |
| 298 | |
| 299 | dialogContainer.attachTemplatePortal( |
| 300 | new TemplatePortal<C>(componentOrTemplateRef, null!, context, injector), |
| 301 | ); |
| 302 | } else { |
| 303 | const injector = this._createInjector(config, dialogRef, dialogContainer, this._injector); |
| 304 | const contentRef = dialogContainer.attachComponentPortal<C>( |
| 305 | new ComponentPortal( |
| 306 | componentOrTemplateRef, |
| 307 | config.viewContainerRef, |
| 308 | injector, |
| 309 | null, |
| 310 | config.bindings, |
| 311 | ), |
| 312 | ); |
| 313 | (dialogRef as {componentRef: ComponentRef<C>}).componentRef = contentRef; |
| 314 | (dialogRef as {componentInstance: C}).componentInstance = contentRef.instance; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Creates a custom injector to be used inside the dialog. This allows a component loaded inside |
no test coverage detected