Murhaf Sousli
Murhaf Sousli

Reputation: 13296

How is cdkPortal different from ngTemplateOutlet

Why should one use cdkPortal over the built-in directives ngTemplateOutlet and ngComponentOutlet in Angular. aren't both of them provide the same functionality? Are there specific features in the CDK Portal that doesn't come with the built-in directives?

Upvotes: 9

Views: 1629

Answers (1)

Jota.Toledo
Jota.Toledo

Reputation: 28434

If you look at the first example in the cdkPortal docs, you will notice one big advantage/commodity:

cdkPortalOutlet unifies the functionality of ngTemplateOutlet and ngComponentOutlet by allowing devs. to embed both templates and components into the view dynamically.

Furthermore, ComponentPortal allows to dynamically pass Injector instances, which can become handy in cases where you need finer control over the dependency resolution of the to-be-embedded component.

Upvotes: 10

Related Questions