Yes, I did it, as you described in your second option.
I created a directive that loads a specific template, which then contains other directives based on a data type attribute.
directive("dynamicFormInput", ['$http', '$templateCache', function($http, $templateCache){ return { restrict: 'E', //currently need model for map center otherwise can be removed, need to set default in map directive scope: {model: '=', section: '='}, template: '<ng:include src="tpl"></ng:include>', link: function(scope, iElement, iAttrs) { var sectionToLoad = ""; switch(scope.section.sectionTypeId) { case 1: sectionToLoad ='partials/survey/textInput.html'; break; case 2: sectionToLoad = 'partials/survey/selectOneOption.html'; break; case 3: sectionToLoad = 'partials/survey/multiSelectOption.html'; break; case 4: sectionToLoad = 'partials/survey/boolean.html'; break; case 5: sectionToLoad = 'partials/survey/textInput.html'; break; case 6: if(scope.section.sectionId == 13) sectionToLoad = 'partials/survey/addressSelection.html'; else if(scope.section.sectionId == 24) sectionToLoad = 'partials/survey/contactForm.html' break; } if(sectionToLoad!="") { $http.get(sectionToLoad, {cache:$templateCache}); scope.tpl=sectionToLoad; } } } }])
Usage then looks like:
<accordion close-others="true"> <accordion-group ng-repeat="section in sections" ng-class="{'isGroundTruthed':section.userId==73}" heading="{{section.sectionName}} ({{displaySelection(section)}})"> <dynamic-form-input section="section"> </dynamic-form-input> </accordion-group> </accordion>
You can ignore the accordion that I just used to somehow repeat it so that each section develops.
Edit Just cleared my directive code.
source share