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

Use transclude scope for inline node templates #81

Open
jtrussell opened this issue Sep 24, 2015 · 5 comments
Open

Use transclude scope for inline node templates #81

jtrussell opened this issue Sep 24, 2015 · 5 comments

Comments

@jtrussell
Copy link
Contributor

I'd like to see what it would take to get rid of the need for wrapping transcluded node templates in a script tag so that folks can use functions/variables in the transcluded scope within their templates.

E.g. this:

<div ivh-treeview="fancy.treeData">
   <div custom-node-template scope-var="fancy.hooray"></div>
</div>

Instead of this:

<div ivh-treeview="fancy.treeData">
  <script type="text/ng-template">
    <div custom-node-template scope-var=":'("></div>
  </script>
</div>

Currently the former will generate a number of compilation errors.

See #70

@christophercr
Copy link

christophercr commented May 29, 2016

Hi, I have player around with the node templates and the tree compilation, and I haven't found a way to get rid of the wrapper of the transcluded templates (either with a script tag or with ng-include)

On the other hand, I could finally find a solution to use the transcluded scope in the node templates, obviously, because of the script or ng-include wrapper mentioned above, the way to have access to the transcluded scope is with $parent, like this (following the example of your comment):

<div ivh-treeview="fancy.treeData">
  <script type="text/ng-template">
    <div custom-node-template scope-var="$parent.fancy.hooray"></div>
  </script>
</div>

You can check my changes in the link below and let me know your thoughts on this so I can create the PR for this.

christophercr referenced this issue in christophercr/angular-ivh-treeview May 29, 2016
…iables from such scope can be used in the node template (with $parent)
@jtrussell
Copy link
Contributor Author

That's interesting. I wouldn't want to advocate using $parent in templates directly but if we can transparently expose that scope to the template I'd be on board :).

@christophercr
Copy link

Yes, the transcluded scope is transparently exposed (because the new scope prototypically inherits from that).

And regarding the $parent, I know, I don't feel 100% comfortable using it neither but this is due to the scriptor ng-include wrapping the template. As soon as I try to remove it, there is a compilation error due to the ivhTreeview directive being required, maybe something to do with the order in which the directives are compiled.

If we find a way to get rid of such wrapper then it would be great but so far this is the best I could do.

@christophercr
Copy link

Hi, do you think this feature could also be part of the v2? If so, I can submit the corresponding PR.

@jtrussell
Copy link
Contributor Author

I'd love to get this in v2, we'd just want to make sure we got appropriate tests added as well.

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

No branches or pull requests

2 participants