I have an angular app animals
, which displays a picture of an animal depending on the current route location. For example, /dog
will display dog picture and /cat
will display the cat picture on the page.
To accomplish it, I have created 3 feature modules - AnimalBoxModule
, CatModule
and DogModule
. AnimalBoxModule
has a component AnimalBoxComponent
and a service AnimalService
. AnimalBoxComponent
uses AnimalService.getPicture()
to get the image of the animal. DogModule
and CatModule
has DogService
and CatService
which can be used to provide custom implementation of AnimalService
to display picture of cat and dog respectively.
I am rendering <animal-box></animal-box>
in the AppComponent
. To display the right picture of animal, I have to provide service implementation (CatService
or DogService
) depending on the current route location. How is it possible in Angular?
Thanks in Advance
Edit
I dont want to make any changes in AnimalBoxComponent
which is using the service, because I am presenting it as a reusable component. IMO, it would not be a good idea to change it whenever we want to extend this app to have more animal services.