I am trying to pass the url of a template using a scope variable. The volume will not change, so the template does not need to be updated based on it, but at present the scope variable is always undefined.
<div cell-item template="{{col.CellTemplate}}"></div>
Ideally, the directive would be:
.directive("cellItem", ["$compile", '$http', '$templateCache', '$parse', function ($compile, $http, $templateCache, $parse) { return { scope: { template: '@template' }, templateUrl: template
However, this does not work. I tried many different permutations while doing the same concept, and this seems the closest, however it still doesn't work.
.directive("cellItem", ["$compile", '$http', '$templateCache', '$parse', function ($compile, $http, $templateCache, $parse) { return { scope: { template: '@template' }, link: function (scope, element, attrs) { var templateUrl = $parse(attrs.template)(scope); $http.get(templateUrl, { cache: $templateCache }).success(function (tplContent) { element.replaceWith($compile(tplContent)(scope)); }); } }; }])
I also tried using ng-include, but this also does not evaluate scope variables before compilation. The value of the CellTemplate comes from a database call, so it is completely unknown before evaluation. Any suggestions for getting this work would be greatly appreciated!
Edit: I am using angular 1.0.8 and cannot upgrade to a newer version.