Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Support recursive trees of directives #8379

Closed
caitp opened this issue Jul 28, 2014 · 7 comments
Closed

Support recursive trees of directives #8379

caitp opened this issue Jul 28, 2014 · 7 comments

Comments

@caitp
Copy link
Contributor

caitp commented Jul 28, 2014

I had some ideas about implementing this during the meeting, so I might have a go at bikeshedding something over the next few weeks.

What it comes down to is basically conditionally inserting DOM into a compiled template, based on some state. Sort of an implicit ng-if that gets resolved at compile-time, or else prevents ng-if from recursively linking the same template.

Anyways, I'd like to sort out a way to do that because it's a pretty cool and useful structure, and other implementations (like http://caitp.github.io/ui-comments/#/) have depended on some ugly hacks which are better to avoid.

I'm sure this has been proposed already, but I can't find any of those issues right now.

Anyways, I'll throw something together and people can see what they think

use cases

  • Comments
  • Org-charts
  • Graphs
  • Product charts
  • etc...
@caitp caitp self-assigned this Jul 28, 2014
@caitp caitp added this to the Backlog milestone Jul 29, 2014
@lgalfaso
Copy link
Contributor

@caitp we use a directive that looks somehow like this

mainModule.directive("recursive", ['$compile', function ($compile) {
  return {
    restrict: "EAC",
    priority: 100000,
    compile: function (tElement) {
      var contents = tElement.contents().remove(),
        compiledContents;
      return function (scope, iElement) {
        if (!compiledContents) {
          compiledContents = $compile(contents);
        }
        compiledContents(scope, function (clone) {
          iElement.append(clone);
        });
      };
    }
  };
}]);

@caitp
Copy link
Contributor Author

caitp commented Jul 30, 2014

there are workarounds, but they literally all suck, every single one of them. Code like that is terrible, because really these trees aren't all resolved statically --- sometimes new tree branches can be added at runtime, which this doesn't support --- and adding support for that, while doable, is a huge ugly hack!

I'm not sure how this is going to work though, I didn't get very far with my prototype yet :p

@lgalfaso
Copy link
Contributor

Fully agree, this is an ugly hack. I just was not able to find something that works better without some refactor to $compile

@lord2800
Copy link

There's another usecase I can think of off the top of my head: infinitely nested submenus (to the limit of how you render them on the screen).

@btford btford removed the gh: issue label Aug 20, 2014
@caitp
Copy link
Contributor Author

caitp commented Jan 23, 2015

this is too hard to accomplish in this codebase

@caitp caitp removed their assignment Jan 23, 2015
@Narretz
Copy link
Contributor

Narretz commented Jan 21, 2016

Dupe of #8536

@Narretz Narretz closed this as completed Jan 21, 2016
@jeme
Copy link

jeme commented Feb 25, 2016

We are still happily using https://github.com/dotJEM/angular-tree allot (yes, i created that)... Optimizations, improvements etc. are more than welcome btw...

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

No branches or pull requests

6 participants