user3384985
user3384985

Reputation: 3017

Angular 4 - Remove current dynamic component programmatically

I have created some dynamic components like -

<div>
  <ang-textfield></ang-textfield>
  <ang-textarea></ang-textarea>
  <ang-checkbox></ang-checkbox>
</div>

Within specific dynamic component there are some elements like -

<ang-textfield>
  <input type="text" />
  <button>Settings</button>
  <button (click)="remove_component()">Remove</button>
</ang-textfield>

I want to remove current component after clicking Remove button.

How can i do that?

Here is the plunker

Upvotes: 5

Views: 3046

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 19630

You can Pass the component factory as a Reference to the Dynamic Build Component and then in the Dynamic Component Have a button Destroy .

This Gist will give you a Clearer Idea.

A live Example

Upvotes: 2

Related Questions