I understand the basic features of Angular Controllers and Directives but I am struggling to see how I can best apply them to wrap the Dynatree tree widget that we use.
The issue is that Dynatree normally has its own means of retrieving data via ajax and populating itself - and normally you do this by calling its "appendAjax" method to append data to a particular tree node - i.e its all one operation.
I know that I could separate the call to the Ajax method and place this in the Controller storing the result of the ajax call in my own tree object - then I could watch for changes to that treeobject in my directive and then update the Dynatree widget manually. But the tree data I am dealing with is large and complex and it seems rather inefficient to have to maintain my own tree structure in the controller when dynatree already has its own tree structure.
My feeling is that in this case I really don't need a controller and instead I could just wrap up the Dynatree inside a directive and essentially keep using it the way I have always used it but this doesn't seem to work - and this is probably where my lack Angular knowledge about Directives occurs. So I have a few questions:
1] Is it considered bad practice to have any kind of ajax call inside a directive?
2] If so, how should I wrap this 3rd party control that likes to do things a certain way?Do I really need maintain my own duplicate tree structure in my Controller?
3] If it is deemed ok to make Ajax calls in a Directive how do I ensure the ajax method runs in the Directive? (I'm assuming this is the cause of my problems)