それを機能させるには、テンプレートを最初にコンパイルしてスコープで実行し ({{baz}} を置き換えるため)、次にコンパイルして再度実行し、"foo-thing" ディレクティブを実行する必要があります。可能ですが、おそらく他の問題を引き起こす可能性があります。
あなたができることは、別のディレクティブを作成するディレクティブであるディレクティブ ファクトリのようなものを作成することです。次に例を示します。
<!doctype html>
<html ng-app="myApp">
<head>
<script src="http://code.angularjs.org/1.1.2/angular.min.js"></script>
<script type="text/javascript">
var myApp = angular.module("myApp", []);
myApp.directive('factory', function($compile) {
return {
restrict: 'A',
scope: {
type: '=factory'
},
replace: true,
link: function($scope, elem, attrs) {
var compiled = $compile('<'+ $scope.type +'></'+ $scope.type +'>')($scope);
elem.append(compiled);
}
};
});
myApp.directive('concrete', function() {
return {
restrict: 'E',
template: "<div>I'm concrete!</div>",
link: function($scope, elem, attrs) {
}
};
});
function MyCtrl($scope, $timeout) {
$scope.directiveType = "concrete";
}
</script>
</head>
<body>
<div ng-controller="MyCtrl">
<div factory="directiveType"></div>
</div>
</body>
</html>