Hi everyone, I have a quick question.. I'm working on a directive that includes an ng-repeat and transclude, with several child directives inside it that need to inherit specific objects from each iteration...
So far, I've only managed to achieve this by using scope.$parent.. but I'm not too keen on this approach because if the parent changes, the scope.$parent chain could get longer and messier...
My question is, how can I pass each iteration object to the children directives? I've tried using require and maybe $broadcast.. but haven't been successful in sending the specific iteration object...
<div demo-parent>
<div demo-child1></div>
<div demo-child2></div>
</div>
var demo = [obj1, obj2, obj3];
demo.directive('demoParent', [function() {
return {
scope: true,
transclude: true,
template: '<div ng-repeat="d in demo" ng-transclude></div>'
]
}]);
demo.directive('demoChild1', [function() {
function link(scope, el, attr) {
scope.someInfo = the specific info from parent; // now with scope.$parent.$parent.d
}
return {
scope: true,
transclude: true,
template: '{{someInfo}}',
link: link
]
}]);
demo.directive('demoChild2', [function() {
function link(scope, el, attr) {
scope.someInfo = the specific info from parent; // now with scope.$parent.$parent.d
}
return {
scope: true,
transclude: true,
template: '{{someInfo}}',
link: link
]
}]);
demoChild1 and demoChild2 are within demoParent in the markup but separate directives