I want to develop a search component. Here is the following use case:
- This component calls a service with search's terms parameters.
- The service call the api endpoint and returns the resulting objects as a collection.
- The component display the results in the template.
I want to write only one search component able to call different service depending on the case. Imagine I have two service:
- SearchInMaleEmployeeService
- SearchInFemaleEmployeeService
Both of these services implements a search function returning a list of employee. I would like to tell my component which service depending on the case. In C#, we can use interface to tell the component constructor which service to use.
How can I do that in Angular2?
Bonus question: How can I say to my component which template to use to render the search results depending of the type of object returned by the service?
See Question&Answers more detail:os