Set Properties on Dynamically Created Angular 2 Components

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

When you generate Angular 2 components, you’re still able to access the component instance to set properties and invoke methods from the component class.

St Clair
~ 8 years ago

Hi, I have a detachRow() method on the dynamically created component that detaches a newly created sibling of the container. Now, when button is clicked the detachRow() is invoked. I receive the row created by an @Input as you described, but the #container is part of the parent. So I will have to send an event that the parent can intercept with the index of the container to delete the appropriate component.

Now, the parent itself is instantiated by the router by a button. In this scenario, how can I communicate with the router-instantiated parent from the dynamically created child to send the row index of the dynamically created child so the parent can then use the index to delete the appropriate siblings from the container.

Hope this is clear. And thanks.