Markup
<div multiple-form
directive-data='directiveData'
ng-attr-template-url="{{box.key == 'experiences'? 'experiences-form.php':'education-form.php'}}"
item="item"
forms="forms"
form-name="{{box.key}}{{item._id}}"
onsave="updateMultipleUser(box.key, item._id, $data)"
onreset="formAction($formName, 'reset')"
cancel="formAction($formName, 'cancel')"
>
</div>
Then your function templateUrl will be
templateUrl: function(tElement, tAttrs) {
$timeout(function(){
return tAttrs.templateUrl;
})
}
Not sure if this will work or not.
Update
Another instructive way is to load the template from the link function and add it from there yourself, and not have a call template through templateUrl
HTML
<div multiple-form
directive-data='directiveData'
template-path="{{box.key == 'experiences'? 'experiences-form.php':'education-form.php'}}"
item="item"
forms="forms"
form-name="{{box.key}}{{item._id}}"
onsave="updateMultipleUser(box.key, item._id, $data)"
onreset="formAction($formName, 'reset')"
cancel="formAction($formName, 'cancel')">
</div>
Directive
{
restrict: 'A',
replace: true,
scope: {
directiveData: '=',
onsave: '&',
onreset: '&',
cancel: '&',
formName: '@',
forms: '=',
item: '=',
templatePath: '@'
},
controller: controller,
link: function(scope, element, attrs){
var template = getTemplate();
element.append($compile(template)(scope));
}
}
, ,
$templateCache
$templateCache angular $templateCache ,
app.run(function($templateCache){
$templateCache.put('myTemplate.html', '<div>myTemplate</div>')
})
, $templateCache.get('myTemplate.html')
$templateCache script type="text/ng-template"
<script type="text/ng-template" id="myTemplate.html">
<div>myTemplate</div>
</script>
$http.get
, $http.get('myTemplate.html') , , , html- . html .
ng-include
ng-include. div, ng-include template-path <div ng-include="templatePath"></div>, div. div, <ng-include src="templatePath"></ng-include>. . , ng-repeat.