I'm facing an issue with calling a function in ng-init within my HTML file. The function is responsible for making an API call and collecting data, which is then assigned to a scope variable and passed to a directive.
Initially, the controller gets executed first. However, before the API call completes, the directive is triggered. As a result, the scope variable passed to the controller remains undefined.
App.directive('foldertree', function () {
return {
restrict: 'A',
scope: {
'inputfromapicall': '=',
'fileName': "="
},
link: function (scope, element, attrs, ngModelCtrl) {
return $timeout(function() {
$('#divid').fileTree({
root: scope.inputfromapicall, //undefined
script: '/project/current/source/data/jqueryFileTree.jsp',
expandSpeed: 1,
collapseSpeed: 1,
multiFolder: false
}, function (file) {
scope.fileName = file;
scope.$apply();
});
});
}
};
});
The above represents my directive code.
I apologize for any confusion caused by my initial question. I am hopeful that someone can assist me in finding a solution to this problem.