简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM