DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

NgComponentOutlet input bindings

You might not be familiar with ngComponentOutlet in the first place, so let's explain what the directive does.

Let’s consider the following template syntax:

Image description

The above code would load a dynamic component into the ng-container. Assigning a new component type to componentTypeExpression would display it in that container.

Here’s a basic example that shows a HelloComponent in the component outlet:

Image description

This feature of Angular allows us to pass input values to that component.

Let's assume that HelloComponent looks like this:

Image description

We can bind a value to the name input as follows:

Image description

And that does the trick! You can see an example in action on Stackblitz here. inputs is an object that can have as many keys as needed. In my example, there is only one: name.


Let’s get connected! You can find me on:

Top comments (0)