I'm looking for a good practice concerning using one component with multiple services.
I have a side navigation menu with 7-8 items in it. Clicking on them should open up a component to edit a simple form, and send the updated data to a service that corresponds to the selected navigation item.
// responses-routing..
const responsesRoutes: Routes = [
{
path: 'responses',
component: ResponsesComponent,
children: [
{
path: '',
component: ResponsesHomeComponent
},
{
path: ':type/:childUrl', <----- here
component: ResponsesEditComponent
}
]
}
];
I'm currently using one component (ResponsesEditComponent) to
1) Get the "type" and "childUrl" fields from the url (This url is navigated to using the router and the side navigation menu. The params are extracted using activatedRoute)
2) Take very basic user input
3) Make a service call to send taken input. The decision to use a service depends on the "type" and "childUrl" fields received from the parameters.
The 7-8 menu items will have sub-items at some point, which also will be using the services that belong to their parent menu item.
The current system may work if I proceed with it, however I feel there should be a better way to handle this. Injecting 8 services to the service, and having to decide on which service to use on every submit button click doesn't feel like the best way to go with it.
I'm considering to
- separate the one route into 8 routes
- use 8 components instead of 1, each corresponding to a menu item
- inject 1 corresponding service to each component
but it seems to be just repetitive work.
Would you mind explaining how you would approach such a scenario, or pointing out a related concept I might not be familiar with?
Cheers.