angular-bootstrap-nav-tree icon indicating copy to clipboard operation
angular-bootstrap-nav-tree copied to clipboard

treeControl manipulations don't work "right away"

Open wz2b opened this issue 8 years ago • 2 comments

I have a number of places where I want to do some tree manipulation as soon as the tree data is loaded. This really gets to the root of some other unanswered issues about what happens when you load a tree with $resource. In my case, the ngResource call is wrapped in a service that returns tree data as a promise. Example:

var self = this;
someService.loadTree().then(function (loadResult) {
    self.treeData = loadResult;
}).then(function() {
    self.treeControl.select_branch(this.initialBranch);
});

This doesn't work at all. Yet if I do it in some delayed fashion (e.g. user pushes a button) it works fine.

I can't figure out if the problem is a scope/digest issue, though I don't think so. But I know this for sure: I don't want to fix it with $interval. And, while I could try to do some magic with directive 'require' that sees a little too intrusive into the privates of abnTree. So I'm looking for a cleaner solution.

wz2b avatar Dec 16 '15 02:12 wz2b

Have you found a cleaner solution?

trondhuso avatar Jan 21 '16 12:01 trondhuso

The cleanest way that I've found to do this sort of thing is to manipulate the data yourself in the promise. Instead of using the treeControl you can set expanded = true on the branches you want expanded, for example. It's basically duplicating code though. :\

The other problem is that this approach won't work for all the available treeControl functions. I'm not sure how to asynchronously set the selected branch, since that's tracked internally by ABNTree in the select_branch function. You can still do it in your data, but the function won't track your initially selected branch.

skylarjhdownes avatar Feb 03 '16 21:02 skylarjhdownes