Is there a way to dynamically load templates into an Angular app based on a parameter within a ng-foreach loop?
<body ng-app="MyApp" ng-controller="ExampleController as example">
<div ng-repeat="item in example.items" class="someClass" ng-switch="item.type">
<!-- Load different templates depending on the value of item.type -->
</div>
</body>
Check out this Fiddle for reference: https://jsfiddle.net/rsvmar2n/1/
Any suggestions on how to achieve this? I tried using ng-switch: https://jsfiddle.net/rsvmar2n/6/
I'm looking for a more efficient, "angular" approach to implementing this feature.
Edit: Ideally, I would like to avoid making an http request for every partial template that is loaded (as in the case of ngInclude).
Edit2: Ultimately decided to use ng-include along with cached templates. Check out the updated Fiddle here: https://jsfiddle.net/rsvmar2n/24/