Just making sure I am wording my question correctly, but I have not been able to find any information on this specific topic. Imagine I have an AngularJS directive that looks something like this:
angular.module( 'example', [] ).directive(
'exampleDirective', ['$compile', '$http',
function($compile, $http) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var listOfItems = attrs.listOfItems;
var foo = attrs.foo;
var template =
'<ul>' +
'<li ng-repeat="item in ' + listOfItems + '">'+
'<i ng-click="clicked(item)">'+
'{{item.' + foo + '}}'+
'</i>'+
'</li>'+
'</ul>';
element.html('').append($compile(template)(scope));
}
};
}]);
The variable listOfItems is an array containing objects such as
[{'Name': 'this'}, {'Name': 'that'}]
, with foo being Name
.
Now, I want to move the template into its own HTML file and load it using an HTTP call. How should the template be structured in the HTML file? Since the local variables won't be accessible in the file, I'm unsure about what needs to be adjusted. Any advice or suggestions would be greatly appreciated. Thank you.