I'm stuck with dynamic template for a directive. Mainly, the directive that called as a comment.
For example, I have created a directive that should check the type of element and an appropriate template. In the link-function I check attribute type of element in the scope and select required template.
All works fine if I call directive as an attribute or an element. However, if I call it as a comment then nothing happens, the output is empty.
Here the code of that directive:
app.directive('inQux', function ($compile) {
var template, inQux, linker;
template = {
foo: '<div>I\'m foo. {{item.value}}</div>',
bar: '<div>I\'m bar. {{item.value}}</div>'
};
linker = function ($scope, element, attrs) {
var content = $compile(template[$scope.item.type])($scope);
element.append(content);
};
inQux = {
restrict: 'AME',
replace: true,
link: linker
};
return inQux;
});
You can find full example by following the link
So, my question is there a way to replace content for comment-directive?