Developing a custom directive within a controller and implementing it in an ng-repeat loop:
HTML:
<div ng-controller="TestCtrl">
<div ng-repeat="page in pages">
<custom
load-data="loadData = fn"></custom>
</div>
</div>
JS:
The loadData function within the Test directive is invoked in the following manner:
scope: {
loadData: "&"
}
controller: ['$scope', '$element', '$timeout', '$filter', function ($scope, $element, $timeout, $filter) {
$scope.loadData({ fn: function(data) {
//Data calculation.
}});
}
The invocation of loadData from TestCtrl looks like this:
App.controller('TestCtrl', function($scope, $http, $timeout, $rootScope) {
$scope.loadData(data);
}
Although I'm trying to execute the loadData function, it results in an error stating undefined is not a function
. Is there a way to access the child directive's scope externally? I've researched using ng-repeat modifying the scope, but haven't found a solution yet. Attempted methods like $broadcast and $on didn't provide any help.
If anyone could offer assistance, it would be greatly appreciated.
Thank you in advance.