Skip to content

Instantly share code, notes, and snippets.

@juliemr
Created October 6, 2014 22:48
Show Gist options
  • Save juliemr/ffccf5bbe5b88a2d3da9 to your computer and use it in GitHub Desktop.
Save juliemr/ffccf5bbe5b88a2d3da9 to your computer and use it in GitHub Desktop.
Transclusion on ng-app
<!DOCTYPE html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.js"></script>
<script>
angular.module('myApp', []).
directive('sillyDir', function() {
return {
restrict: 'ECA',
terminal: true,
priority: 400,
transclude: 'element',
compile: function (tElement, tAttrs, compileTransclude) {
console.log('compiling sillyDir');
return function (scope, $element, attrs, controller, linkTransclude) {
console.log('linking sillyDir');
// compileTransclude(scope, function(clone) {
// console.log($element);
// console.log(clone);
// $element.empty();
// $element.parent().append(clone);
// });
linkTransclude(function(clone) {
console.log($element);
console.log(clone);
$element.empty();
$element.parent().append(clone);
})
};
}
};
});
</script>
</head>
<body>
<span>
Try grabbing angular.injector($0).injector() from the elements below, and
see that it's always undefined.
</span>
<div ng-app="myApp" silly-dir>
<div ng-view></div>
<input ng-model="name" type="text"/>
<span>Hello {{name}}</span>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment