JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-controller="myController">
<tabulate content="countries" cell="template"></tabulate>
</div>
JavaScript
angular.module("myApp", [])
.controller("myController", function($scope) {
$scope.flags = {
"us": "American Flag",
"ar": "Argentinian Flag",
"jp": "Japanese Flag"
}
$scope.countries = ["us", "ar"];
$scope.template = angular.element('<country country="{{cellData}}" flags="{{flags}}"></country>');
})
.directive("tabulate", function() {
return {
"restrict": "E",
"template": '<table class="tabulate"></table>',
"scope": {
"content": "=content",
"cell" : "=cell"
},
"link": function(scope, element) {
for (var i=0; i<scope.content.length; i++) {
var cellData = scope.content[i];
element.append(
angular.element("tr")
.append(____) // template, compiled with myController's scope extended with `cellData`...
);
}
}
}
})
.directive("country", function() {
return {
"restrict": "E",
"template": '<span class="country"></span>',
"scope": {
"country": "=country",
"flags" : "=flags"
},
"link": function(scope, element) {
element.text(scope.flags[scope.country]);
}
}
})