I want to create a component in Angular2 which will show a table with some data(lets assume sales data of different product P1 and P2). Along with the table I want to allow user to choose option between different type of graphs and based on the graph selection I want to show the graph of shown data in a container below the data table.
I have created a component(lets call it Main) which have as one component, A radio group showing graph type. Now for 10 different graph type, and I have created 10 different graph component for these 10 types.
Approach: I can put all ten component in Main component and based on user selection I show the respective graph component. But this approach would be too costly since Main component shadow dom will have all the graph component. It also present problem If I allow user to select from a range of time and update the shown graph using binding as it will result in updating other graph which are not being shown.
Is there any approach where I can put a generic container in Main component and inject a list of graph component in main component and based on user selection I put the selected graph component in that container. Putting in the container should not disrupt binding.
Just to summarize, I want to find a way to dynamically put the component in a another component. Ideally in Composite Design Pattern it should be fairly easy to determine component in runtime. I am not able to figure that out in angular 2.