Skip to content

Instantly share code, notes, and snippets.

@niisar
Created December 11, 2014 01:52
Show Gist options
  • Save niisar/d9480ebda946c459e192 to your computer and use it in GitHub Desktop.
Save niisar/d9480ebda946c459e192 to your computer and use it in GitHub Desktop.
Directives Which Wraps Elements Via Transclusion
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="js/angular.js"></script>
<script>
myapp = angular.module("myapp", []);
myapp.directive('mytransclude', function () {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.transclude = true;
directive.template = "<div class='myTransclude' ng-transclude></div>";
return directive;
});
myapp.controller("MyController", function ($scope, $http) {
$scope.firstName = "nisar";
});
</script>
<title></title>
</head>
<body ng-app="myapp" ng-controller="MyController">
<mytransclude>This is a transcluded directive {{firstName}}</mytransclude>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment