I'm creating a component that I'd like to use as a child in another component but also as a standalone view.
For instance, component ViewCarsComponent
pairs a list, SmallCarsListComponent
, and a panel for viewing detailed information about a Car
object, CarDetailComponent
. When an item from the list is selected, the Car
object for that item is provided to the details panel via an @Input
and the panel is updated. However, when I navigate to /cars/small/20
, I want to show the detail panel by itself with the details for the Car
with ID 20. This one component can thus take a Car
object, provided by the sibling list component via @Input
, or a number
as a URL parameter that it can then use to make its own query.
Is there a better way of doing this? Is there some middleware that I should be writing that can retrieve the Car
corresponding to the ID provided as a URL parameter, then hand that off to CarDetailComponent
, so said component never needs to make the request for the Car
object itself? Should two separate components, one designed for @Input
and one designed for URL parameters be made?