-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($compile): support DOM nodes as template values #5508
Conversation
|
||
|
||
it('should accept DOM nodes as a template', inject(function($compile, $rootScope) { | ||
if (!(msie < 9)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only testing this on browsers which are not IE8, due to IE8 apparently not supporting SVG nodes... but I don't actually know if it would really fail on ie8
Special content types, such as SVG content or table content, can not be used in many cases due to generating a document fragment which does not support the particular template content type being used. This patch enables special content such as SVG or table content to be used by making the template a DOM node or collection of DOM nodes, rather than strings. The test demonstrates how this can be used to replace the directive node with SVG elements, or similar.
|
||
directiveValue = denormalizeTemplate(directiveValue); | ||
if (!elementTemplate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means that DOM templates won't be denormalized. that's not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the individual nodes would end up denormalized later on though, no? Actually, I guess not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
denormalization is about taking all {{ }}
bindings and turning them into whatever the the interpolation start and stop symbols are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to happen so that reusable components can be built with the usual {{ }}
bindings but then in the actual app we use whatever symbols the developer configured.
I think the issue with denormalization is an important one and I don't know how to solve that right now without traversing the whole dom fragment |
otherwise this looks like an interesting feature |
It would be easy to solve the denormalization problem by just having every node walked by the compiler denormalize its own text, that doesn't seem too bad. |
02dc2aa
to
fd2d6c0
Compare
Special content types, such as SVG content or table content, can not be used in many cases due to generating a document fragment which does not support the particular template content type being used.
This patch enables special content such as SVG or table content to be used by making the template a DOM node or collection of DOM nodes, rather than strings.
The test demonstrates how this can be used to replace the directive node with SVG elements, or similar.
This could be considered an alternative solution to #5235, #2848, #1459, #3647, #3241 and others, with the benefit that it's less work to implement in the compiler, but slightly more work for the user, and doesn't support templateUrl templates.