Created
September 10, 2014 10:31
-
-
Save psdcoder/8f135f3d0ed2ab0c5f51 to your computer and use it in GitHub Desktop.
Bind transcluded dom to directive scope
This file contains hidden or 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> | |
| <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