I am building a modal component in Angular 2 (and TypeScript) that will have different views/pages. It won't have tabs, but the concept is pretty similar. Basically I am struggling to find an approach to doing this.
Within my modal component, I want to output the different views/pages. Each one should be a component itself, because they don't have any markup in common. Plus, they will fetch data from service classes, so I need to be able to write specific logic for each view.
Basically what I want is something like:
// Within my modal component's template
<div *ngFor="#view of views">
// Render view component here
</div>
Where views
could be an array of the components, for instance. My first and main problem is that I am not sure how to output a collection of my views (components).
How can I output a collection of components within another component?
Also, I need a way to hide and show views, which is the only thing the views have in common. I was thinking of adding an isActive
variable to the views and showing/hiding them based on that. Would it be bad practice for the views components to either implement a ModalView
interface or extend from a base class to add this logic? From my modal component, I want to be able to control which view is displayed, so I need the views to have this logic in common.
I hope it is clear what I want to do. The solution may be simple, but right now I am a bit confused on how to go about it. A code example would be much appreciated!