Perhaps, but when your download template depends on some area data, you can no longer use the property of the templateUrl directive, and you will be required to use the lower-level API, namely $http and $compile .
Approximately what you need to do (it is possible only in the binding function) is to get the contents of the template using $http (do not forget to include $templateCache !), And then compile the contents of the template manually.
It would seem that this is a lot, but in practice it is quite simple. I would suggest looking at the ngInclude directive sources where this template is used.
Here is the skeleton of such a directive:
app.directive('boom', function($http, $templateCache, $compile, $parse) { return { restrict: 'E', link: function(scope , iElement, iAttrs) { var boom = $parse(iAttrs.data)(scope); $http.get('myTemplate'+boom, {cache: $templateCache}).success(function(tplContent){ iElement.replaceWith($compile(tplContent)(scope)); }); } } });
assuming it will be used as <boom data='name'></boom> . Working snippet here: http://plnkr.co/edit/TunwvhPPS6MdiJxpNBg8?p=preview
Please note that I changed the attribute rating from {{name}} to attribute parsing, since the template should probably be defined only once at the beginning.
pkozlowski.opensource Jan 31 '13 at 18:09 2013-01-31 18:09
source share