wix-incubator / angular-tree-control

Angular JS Tree
http://wix.github.io/angular-tree-control
MIT License
708 stars 276 forks source link

No nice way to make classes dynamic based on node properties #74

Open jcamins opened 9 years ago

jcamins commented 9 years ago

In order to handle a "disabled" state and model-aware icons, it would be really useful to be able to inject ng-class into, e.g., the li tag for each node. Would you consider a PR that adds this feature?

Right now I'm doing the following, which works but doesn't seem quite idiomatic: $scope.indicatorOptions = { injectClasses: { li: 'disabled-{{node.disabled}}' } };

seiyria commented 9 years ago

@jcamins I can't even get that example to work. How are you getting angular to evaluate your inject classes?

Edit: I got it to work only on leaf nodes -- iExpanded and iCollapsed aren't able to be interpolated it seems. Working on that right now.

alinnert commented 9 years ago

I need this feature too. I imagine it to work as following:

$scope.treeOptions = {
    injectClasses: {
        li: function (node) {
            return node.disabled ? 'disabled' : '';
        }
    }
};

I've tried this but it doesn't work.

alinnert commented 9 years ago

I just created a pull request to add this ability. Unfortunately I can't use the existing properties of injectClasses in an easy way (had no reference to node at this point) so I had to create a new property.