Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 - Remove current dynamic component programmatically

Tags:

angular

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

like image 611
user3384985 Avatar asked Oct 30 '22 01:10

user3384985


1 Answers

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

like image 122
Rahul Singh Avatar answered Dec 03 '22 15:12

Rahul Singh