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

treeControl manipulations don't work "right away" #92

Open
wz2b opened this issue Dec 16, 2015 · 2 comments
Open

treeControl manipulations don't work "right away" #92

wz2b opened this issue Dec 16, 2015 · 2 comments

Comments

@wz2b
Copy link

wz2b commented Dec 16, 2015

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.

@trondhuso
Copy link

Have you found a cleaner solution?

@skylarjhdownes
Copy link

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.

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

3 participants