I am trying to call a Function in ng-init i my html file. That function makes a API call and gives the data. I assigned that data to a scope variable and pass that scope variable to directive.
Controller is hitting first. But before APIi call completes directive got hitted. So the scope variable which i am passing to controller is as 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();
});
});
}
};
});
Above is my directive code
Sorry for posting the vague question.Hope some one help me with the fix.