Answer the question
In order to leave comments, you need to log in
Why isn't the template rendered when using $compile in a directive?
directive('addSubtitle', function($compile) {
var subtitleTemplate =
'<div class="entry-photo">' +
'<h2> </h2>' +
'<div class="entry-img">' +
'<span>' +
'<a href="">' +
'<img ng-src="" alt="entry photo">' +
'</a>' +
'</span>' +
'</div>' +
'' +
'<div class="entry-text">' +
'<div class="entry-title"></div>' +
'<div class="entry-copy"></div>' +
'</div>' +
'</div>';
var getTemplate = function(contentType) {
var template = '';
switch(contentType) {
case 'subtitle':
template = subtitleTemplate;
break;
case 'video':
template = videoTemplate;
break;
case 'notes':
template = noteTemplate;
break;
}
return template;
};
var linker = function(scope, element, attrs) {
element.click(function(){
console.log(attrs.contentType);
console.log(scope.type);
$compile(getTemplate(scope.type.type));
});
};
return {
restrict: "EA",
scope: {
type: '=contentType'
},
replace: false,
link: linker
};
});
Answer the question
In order to leave comments, you need to log in
Read the documentation for the $compile service.
Your call returns a function that can be called with the scope parameter and get the element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question