I'm working with two directives, let's call them:
angular.module('app').directive('directiveX', directiveX);
function directiveX(){
return {
restrict: 'E',
transclude: true,
scope: {},
templateUrl: 'directiveX.html',
controller: function($scope){
$scope.data="some data";
}
};
}
And the second one:
angular.module('app').directive('directiveY', directiveY);
function directiveY(){
return {
restrict: 'E',
require: '^directiveX',
transclude: true,
scope: {},
templateUrl: 'directiveY.html',
link: function(scope, elem, attrs, directiveXController) {
console.log("directiveY linked");
}
};
}
HTML structure for directiveX:
<div>
<!-- content here -->
<div ng-transclude></div>
</div>
HTML structure for directiveY:
<div>{{data}}</div>
Now, I want to use them in this manner:
<directive-x>
<directive-y></directive-y>
</directive-x>
How can I establish communication between them using require and ng-transclude and ensure that both templates are rendered? For instance, I wish to display the data variable from directiveX in the directiveY template. As a newcomer to directives and transclusion, any guidance would be appreciated.