はい、2番目のオプションで説明したようにこれを行いました。
データの type 属性に基づいて他のディレクティブを含む特定のテンプレートをロードするディレクティブを作成しました。
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;
}
}
}
}])
使用法は次のようになります。
<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>
各セクションが折りたたまれるように、たまたまそれを繰り返すアイテムとして使用したアコーディオンは無視できます。
編集
ディレクティブコードをいくつかクリーンアップしました。