Created
October 6, 2014 22:48
-
-
Save juliemr/ffccf5bbe5b88a2d3da9 to your computer and use it in GitHub Desktop.
Transclusion on ng-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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