-
Notifications
You must be signed in to change notification settings - Fork 132
Can a component have it's own sub components + viewports? #117
Description
Giving the fact that each component is somehow isolated and independent, I wonder if it's possible to build a component that introduces sub components and viewports for itself, without coming from an outer routing.
Here's what I mean: We know that we can configure the router to map a route to more than one component like this:
app.controller('AppController', function ($router) {
$router.config([
{
path: '/',
components: {
viewportA: 'navigation',
viewportB: 'main'
}
}
]);
});
Now, when routing to /
the components navigation
and main
are loaded into the viewports viewportA
and viewportB
.
Now imagine the following scenario:
We have our AppController
that maps a route to a componentA
like this:
app.controller('AppController', function ($router) {
$router.config([
{
path: '/',
component: 'componentA'
}
]);
});
Now, the interesting part, componentA
has a template like this:
<h1>Component A</h1>
<router-view-port="left"></router-view-port>
<router-view-port="right"></router-view-port>
And a router configuration like this:
app.controller('ComponentAController', function ($router) {
$router.config([
{
path: ???
components: {
left: 'subComponentA',
right: 'subComponentB'
}
}
]);
});
So componentA
is a component, as we know, and it as it's own controller and introduces it's own viewports with it's own router. But as we can see in the code snippet, it's not very clear to what route that maps.
My question is, is that possible at all? That a component is so self-contained that it truly introduces it's own viewports and router? Or do I always have to define my custom "wrapper" route at application level that says "Hey I have this route here and we want to load two components in it.". But that also means, the start template (index.html
) needs to have two viewports.
I hope my question is clear, if not please let me know!