How to clone duplicate components on button click

1,402 views
Skip to first unread message

Surya PrakasH

unread,
Feb 27, 2021, 1:33:00 PM2/27/21
to Angular and AngularJS discussion
Hi All,

Please help me on below.
My client requirement is duplication of existing component to multiple with form binding values.


example: I used Output and EventEmitter it is working fine through parent component, but i don't know how to write copy button code in dynamically created component. Anyone please help on this, below is my stackblitz url.

When i click copy button on initially loaded component multiple duplicate components and deleting components are working fine.

https://stackblitz.com/edit/angular-material-design-o8ushb



Thank you.

khushbu poddar

unread,
Feb 28, 2021, 12:55:32 AM2/28/21
to ang...@googlegroups.com
Hi Surya, 

Here is it mandatory to use the dynamic components? Can't you use an array to render no of components and render it with the help of ngFor?

Thank You.

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/268fae70-0b45-4a2f-91f7-e41331f4110dn%40googlegroups.com.

khushbu poddar

unread,
Feb 28, 2021, 1:24:55 AM2/28/21
to ang...@googlegroups.com
you can also use Input/Output events

https://stackblitz.com/edit/angular-material-design-qgywzw

This code has some minor errors, but you can have the idea by looking into this code
Reply all
Reply to author
Forward
0 new messages