Skip to content

Instantly share code, notes, and snippets.

@psdcoder
Created September 10, 2014 10:31
Show Gist options
  • Select an option

  • Save psdcoder/8f135f3d0ed2ab0c5f51 to your computer and use it in GitHub Desktop.

Select an option

Save psdcoder/8f135f3d0ed2ab0c5f51 to your computer and use it in GitHub Desktop.
Bind transcluded dom to directive scope
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
</head>
<body ng-controller="ParentCtrl">
<test-directive>
<p>Some content <br> {{ test }} </p>
</test-directive>
<script>
angular.module('app', [])
.controller('ParentCtrl', function ($scope) {
$scope.test = 'Test content from parent Controller';
})
.directive('testDirective', function() {
return {
restrict: 'E',
transclude: true,
template: '<div></div>', //or use ng-transclude with default behaviour
scope: true, //create new scope
link: function(scope, element, attrs, ctrl, transclude) {
scope.test = 'Test content from test directive scope';
transclude(scope, function(clone, scope) {
element.append(clone);
});
}
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment