question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: $scope.treeInstance is undefined

See original GitHub issue

I’m using AngularJS 1.4.2 and jQuery 2.1.4

my controller:

angular.module('app.controller', [
    'ngJsTree'
]).controller('AppController', function ($scope, $log) {
   //... 
    var selected_nodes = $scope.treeInstance.jstree(true).get_selected();
}

my template: <div js-tree="treeConfig" ng-model="treeData" tree="treeInstance">

and got: Error: $scope.treeInstance is undefined

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
isaacficommented, Mar 21, 2017

I have the solution, the problem is to use treeInstance direct to the $scope as:

<div id="myTreeId" js-tree="treeConfig" ng-model="treeData" tree="treeInstance">

You have to initialize an object in the controller, for example:

function myCtrl(
        $scope) {
$scope.model = {};
...
}

After this, use the model in your template as: <div id="myTreeId" js-tree="treeConfig" ng-model="treeData" tree="model.treeInstance">

And in the controller: $scope.model.treeInstance, won’t be undefined.

1reaction
ezraroicommented, Feb 18, 2016

@melino you must wait for the ready event of the jsTree before using the api instance. In the controller constructor it will not be available

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get tree instance in controller - Ext 4
I have a small problem to get the instance of my tree in controller. Well, without the MVC pattern it looks like this...
Read more >
TreeInstance - Scripting API
Contains information about a tree placed in the Terrain game object. This struct can be accessed from the TerrainData Object. Properties. color, Color...
Read more >
Tigra Tree Menu PRO
Key Description Accepted Values Default Value icon_48 Icon for a root path to the image icons/base.gif alt_48 Icon for a root alt and title attribute...
Read more >
mstform README
You can modify the mobx-state-tree instance in code as well and the form is automatically updated. ... error : An error message (or...
Read more >
CLI Reference Guide Version 6.7
Interface Error Disable and Auto Recovery Commands 550 ... ipv6 nd ra hop-limit unspecified . ... Adds an administrative scope multicast boundary.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found