I wonder what is the best practice when I have a response that has many different types of objects and looks like that:
[
{"nodeClass":"Entity", "text":"foo","entityfield":"booz"},
{"nodeClass":"User","username":"bar","userfield":"baz"}
]
and I have different templates for all of those:
for Entities:
<div class="{{nodeClass}} capsule">{{entity.text}}:{{entity.entityfield}}</div>
for Users:
<div class="{{nodeClass}} capsule">{{user.username}}:{{user.userfield}}</div>
how would you structure the code and with which angularjs elements (ng-repeat etc) to (re)use the correct templates based on the value of "nodeClass". Keep in mind that I don't want to make a new conditional template except if it is the only solution.
Edit: I have found those approaches: http://onehungrymind.com/angularjs-dynamic-templates/ and if else statement in AngularJS templates and Dynamically displaying template in ng-repeat directive in AngularJS? but they are quite different than my requirements. Especially the last one is the closest to what I want but my templates as usually have different variable names in them..
Thanks