I'm trying to pass an already dynamic value to my directive to fetch a templateUrl for this value. Let me explain with some Sourecode:
<p ng:repeat="cell in field.Cells">
<cell-element handler="{{cell.handler}}"/>
<!-- cell.handler is e.g. "User" -->
</p>
myapp.directive('cellElement', function() {
return {
restrict: 'E',
templateUrl: function (tElement, tAttrs, $compile) {
return '/ajax/' + tAttrs.handler == undefined ? 'foo' : tAttrs.handler +'.html';
},
}
});
Unfortunately, the value of tAttrs.handler is always the literal expression "{{cell.handler}}" instead of the respective value. I tried so many different ways - any guess?
UPDATE:
myapp.directive('cellElement', function() {
return {
restrict: 'E',
scope: { handler: '=handler' },
template: '<ng-include src="\'/ajax/\' + handler"></ng-include>'
}
});
As workaround i used another approach that works. But i would prefer the initial way by using the templateUrl function as i e.g. want to check if "handler" is a valid value.
handler="cell.handler"without curly brackets.