I'm trying to use the jQuery fancy tree plugin with Angular. The source data for the tree comes from an ajax call in my controller. I'm then trying to get that data into my directive and load the tree. Say the service takes 2 seconds to get the data. Heres a cut down version of my code.
HTML
<div tree-view ></div>
SERVICE
angular.module('sc.services', []).
factory('scService', function ($http) {
var scApi = {};
scApi.getsc = function () {
return $http({
url: config.Url.sc
});
};
return scApi;
});
CONTROLLER
angular.module('sc.controllers', []).
controller('scController', function ($scope, scService) {
scService.getsc().success(function (response) {
$scope.sc = response;
});
});
DIRECTIVE
angular.module('sc.directives', [])
.directive('treeView',function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch('sc', function() {
$(element).fancytree({
source: scope.sc
});
});
}
}
});
Jquery loads the fancy tree onto the page (so the directive is being called) but without an data. I also bind the data to a table on the page just to make sure its loading ok and that works. What am I missing?
Is this the correct way to do this?