angularheterogeneous-array

How can I display a heterogeneous list with different templates in angular?


I want to present a list of items of coming from a service, and the items may be of different types. I need to display a different template for each item at runtime. Is there something that selects a template for each item in a collection based on its value or type? For example, xaml has the concept of a template selector.


Solution

  • You can use NgSwitch. Wrap the possible templates in a container, and put the ng switch directive on the container. Put an NgSwitchCase directive on each template. The matching cases will be visible.