I am curious about the best approach to handling a response that contains various types of objects presented like this:
[
{"nodeClass":"Entity", "text":"foo","entityfield":"booz"},
{"nodeClass":"User","username":"bar","userfield":"baz"}
]
Each type of object requires its own template:
For Entities:
<div class="{{nodeClass}} capsule">{{entity.text}}:{{entity.entityfield}}</div>
For Users:
<div class="{{nodeClass}} capsule">{{user.username}}:{{user.userfield}}</div>
How can I structure the code using AngularJS elements (such as ng-repeat) to dynamically use the correct templates based on the value of "nodeClass"? It's important not to create new conditional templates unless absolutely necessary.
Edit: I have come across these resources: and if else statement in AngularJS templates and Dynamically displaying template in ng-repeat directive in AngularJS? However, they don't quite meet my specific requirements. The last one comes close, but my templates often include different variable names.
Thank you!