How can one utilize a string contained within a variable as a template?
For example:
Controller
$scope.items = [
{
name: "Bruce Wayne"
},
{
name: "Lucius Fox"
}
];
$scope.template = "<input ng-model='item.name' type='text'>";
View
<div ng-repeat="item in items">
<div ng-bind-html="<!-- The `template` variable defined in the controller. -->">
</div>
</div>
I've tried $sce.trustAsHtml, which only doesn't connect with the actual scope when using things like ng-model='item.name'. Reading through the $sce docs I don't think that it provides anything that can trust a string as a template.
A fiddle for you to play with.
$rootScopeinstead? or declaring your template in asetTimeout(function(){}, 0)?$rootScopewould still have the item accessible in the$scope, just defined in a parent instead. I don't believe that would change anything.