-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($compile): Allow using functions as templates in directives #1849
Conversation
By the way, I already signed the CLA |
A simple but elegant solution! |
+1. Simple and more customizable.. |
as I understand, in function of template I can't use DI? May be there could be quite easy but very powerfull solution to have "templateExpression"/"templateUrlExpression" properties, where I can use filters. Use case:I could use: So this simple solution (that can use $interpolate service) will give power of DI |
Hmmm... I don't know if that is feasible without touching many lines of code. When using functions as templates, they are called before all the dependencies of the directive get loaded. In order to fix it, we would need to defer the function call after all the other dependencies load. Let me think if I can figure out how to do it as cleanly as possible... |
Why do you need DI for the template/templateUrl function? You can use DI for the directive declaration function, which should cover any needs for the template function.
|
at first glance I like it. I'll sleep on it and will likely merge it tomorrow. |
@mhevery: I've just updated my local repository in order to pass "$compileNode" into the call as you suggested. @IgorMinar, I can't think of a use-case where it would be advantageous to use an asynchronous templateUrl function call. May be I'm missing something... Just to be sure, I intend to follow these steps now:
Am I right? I fear that this could disrupt source code line comments, but I think that could ease the integration of the PR. |
I've just forced the push with the new changes. The original comments from Miško and Igor are still available here: |
I'll take a look tonight. Thanks. |
PR Checklist (Minor Feature)
|
please rebase against latest master (there is a conflict) |
Specs have been reworked and the commit has been rebased. Old comments are still available at lrlopez@1de1f85#test-ng-compilespec-js-P8 |
Added dynamic template support in directives: - The call will pass the element and directive attributes as parameters - This allows generating templates on the fly - It also applies to templateUrl
Oops, I pushed the wrong branch. I hope it works now :) |
I reworked the docs and tests and landed the change as eb53423 in the future please try to write focused tests - tests that test only the functionality you are adding without any other distractions. thanks for the contribution, I'm quite happy about this feature! |
Added dynamic template support in directives:
Closes #1039