How to inject component dynamically based on data type?

  Kiến thức lập trình

I have different sections od the applications (I am using standalone components so don’t want to say modules).

Now, one of the sections is search.
When user does a search, different search result types can be shown.
Let’s say searchResultType1, searchResultType2, searchResultType3. All of them can be shown at once in the list, mixed.

Each searchResultTypeX is implemented in its corresponding section of the app.

I am thinking defining abstract class that all searchResultX types implement but they are all injected into search component as abstract class.

I know how to implement this when I have one, but can’t figure out if there is a way to inject all of them based on data type returned by search.

LEAVE A COMMENT