0

i am very new to angular 2, i have some set of dynamically created divs i want to load per-defined components to those div based on user selection. i tried many blogs to load component dynamically but none of them are clear and simple.

what i'am expecting is to know how to load one component to a div on click of a button.

for example

@Component({
    selector: 'container',
    template: `<div id="container">// need to place the component here on click of a button  //</div>`
 })

if anybody can provide a plunker or solution is highly appreciated

rahul cp
  • 307
  • 1
  • 3
  • 15
  • There is one of Q & A how to do dynamic stuff http://stackoverflow.com/q/38888008/1679310 – Radim Köhler Oct 19 '16 at 11:15
  • Here is the same stuff https://medium.com/nerdlog/angular-2-dynamic-view-and-components-330205fa6896#.yqf9wocpv – yurzui Oct 19 '16 at 11:19
  • Thanks for the quick response. it seems very complex is there any other simple example anybody can give ? like i said on click of a button it should load a component on the container – rahul cp Oct 19 '16 at 11:45

1 Answers1

-2

Define a html component using # inside template

<div #container ></div>

Now you can access this container inside the component class

this.container.innerHTML="YOUR CONTENT";
manu
  • 115
  • 5