I can access controller functions once in my parent directive using the $parent operator, but this does not work in recursive child directives. Below is an example of my code (I've tried to shorten it a bit for this):
//controller example (defined using controllerAs):---
var View2Ctrl = function(){
//function i am trying to access:
this.getNumber = function(){
return 5;
}
.
.
.
angular.controller('View2Ctrl',............
//'comments' directive template:--
<li>
<!-- I'm trying to access the function in here: -->
<!-- below line works just once here, does not load in recursive child directives below: -->
<strong> Number: </strong> {{ $parent.View2Ctrl.getNumber() }}
<!-- below line gets replaced with a recursive child directive again -->
<span class="comments-placeholder" ></span>
</li>
//'comments' directive.js:---
var comments = function($compile){
return {
templateUrl : 'modules/comments/commentsDirective.html',
restrict:'E',
scope:{
collection: '='
},
link: function(scope, element, attrs){
if(scope.collection.data.replies){
var elementResult = angular.element(element[0].getElementsByClassName('comments-placeholder'));
elementResult.replaceWith($compile('<ul ng-repeat="comment in collection.data.replies.data.children><comments collection="comment"></comments></ul>')(scope));
}
}
};
};