AngularJS Example
HTML
<div ng-app="app">
<div ng-controller="ParentCtrl">
<div class="transcludeMe">
<div data-transclude-this="here">
<div class="myDirective"></div>
</div>
</div>
</div>
</div>
CSS
</style>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.css"/>
<style>
JavaScript
angular.module('app', [])
.directive('transcludeMe', function($rootScope){
return {
restrict: 'C',
replace: true,
transclude: true,
template: '<div>transclude here: <div data-transclude-here></div></div>',
compile: function(tElement, tAttributes, transclude){
var transcludeHere = angular.element(tElement[0].querySelector("div[data-transclude-here]"));
var scope = $rootScope.$new();
transclude(scope, function(clone){
for(var x = 0; x < clone.length; x++){
if(clone[x] instanceof HTMLElement){
switch(clone[x].getAttribute("data-transclude-this")){
case "here":
transcludeHere[0].innerHTML = clone[x].innerHTML;
break;
}
}
}
});
}
};
})
.directive('myDirective', function() {
return {
restrict: 'C',
//replace: true,
template: '<div data-ng-click="runTest()">hello</div>',
link: function(scope, element, attrs, controller) {
console.log('link myDirective')
scope.runTest = function(){
alert("clicked");
}
}
}
});
function ParentCtrl($scope){
$scope.foo= false;
$scope.title = "Checkbox title";
}