Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree Instance undefined after the tree is successfully created #23

Closed
cbalves opened this issue Mar 30, 2015 · 8 comments
Closed

Tree Instance undefined after the tree is successfully created #23

cbalves opened this issue Mar 30, 2015 · 8 comments

Comments

@cbalves
Copy link

cbalves commented Mar 30, 2015

Hi, I'm trying to create a directive for a Drag'n'drop tree using ngJsTree. The tree is created and works, but so far I've been unable to use the treeInstance, as it always shows up as "undefined".

I tried to adapt your solution from the #8, and created a new plunker with a simple example of my code, which surprisingly works as expected:
http://plnkr.co/edit/onimKl8iGNyYUkRENW5T?p=preview

In my real application, the console.log for the TreeInstance keeps showing up as undefined, although the implementation is pretty similar. In this Plunker example, I'm not using a controller, but I have tried both approaches with the same unsuccessful result.

Any idea of what might be the problem?

Thanks in advance!

@ezraroi
Copy link
Owner

ezraroi commented Mar 30, 2015

When do you print the TreeInstance to the console?
if in the controller constructor it will not work, only after ready event of the tree is fired you can access it

@cbalves
Copy link
Author

cbalves commented Mar 30, 2015

I print the treeInstance in the readyCB event, just like it's done in your previous plunker example: http://plnkr.co/edit/1PHjOqojZsVlQmP819PW?p=preview

I also created a button to print its value, like the one you have in your demo - "Call Method of Tree Instance" - but since the treeInstance is undefined, I get a "TypeError: Cannot read property 'jstree' of undefined"

@ezraroi
Copy link
Owner

ezraroi commented Mar 30, 2015

If you can't reproduce this in plunker, it will be very hard to for me to help. The treeInsrance property is working fine in tests and in my projects

@Incognito-Nemo
Copy link

Same problem with jquery 2.1.3, angular 1.3.15, jsTree 3.1.0…

@ezraroi
Copy link
Owner

ezraroi commented Apr 9, 2015

Did you manage to reproduce on plunker?

@cbalves
Copy link
Author

cbalves commented Apr 9, 2015

Sorry for the late response. I was finally able to retrieve the treeInstance. In my case, the only solution was to use the ng-controller directive to define the controller (which I avoid using in my project):

  <div ng-controller='myCtrl'>
     <div js-tree="treeConfig" ng-model="treeData" tree="treeInstance"></div>
  </div>

I'm still unable to reproduce the working example of my first plunker or to get the treeInstance without having to use ng-controller.

Thanks a lot for your help and for this great Angular directive! Keep up the good work :)

@ModuloM
Copy link

ModuloM commented Apr 9, 2015

Hi,
I had the same issue and solved it by adding ng-controller and (re)reference the instance in the controller like this:
ctrl.treeInstance = angular.element('#myDivTreeElement') (just in case it helps)

Thanks for this very usefull work!

@ezraroi
Copy link
Owner

ezraroi commented Apr 9, 2015

Happy to see that the directive is being used and thanks for sharing your solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants