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('transcludeHere', function(){
return {
controller: function($transclude, $element, $attrs) {
$transclude(function(clone) {
var l = clone.length;
for (var i=0; i<l; i++){
var child = angular.element(clone[i]);
console.log(child[0]);
var viewName = child.attr('data-transclude-this');
if(viewName){
console.log(viewName)
}
if (viewName && viewName.split(" ")[0] == $attrs.transcludeHere){
$element.append(child);
}
}
});
}
}
})
.directive('transcludeMe', function($rootScope){
return {
restrict: 'C',
replace: true,
transclude: true,
template: '<div>transclude here: <div data-transclude-here="here"></div></div>',
};
})
.directive('myDirective', function() {
return {
restrict: 'C',
replace: true,
template: '<div data-ng-click="runTest()">hello</div>',
link: function(scope, element, attrs, controller) {
scope.runTest = function(){
alert("clicked");
}
}
}
});
function ParentCtrl($scope){
$scope.foo= false;
$scope.title = "Checkbox title";
}