-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(toast): better toast templating allowing comments and sibling elements #6494
Conversation
LGTM. @jelbourn thoughts? |
@@ -289,18 +289,16 @@ function MdToastProvider($$interimElementProvider) { | |||
// Root element of template will be <md-toast>. We need to wrap all of its content inside of | |||
// of <div class="md-toast-content">. All templates provided here should be static, developer-controlled | |||
// content (meaning we're not attempting to guard against XSS). | |||
var parsedTemplate = angular.element(template); | |||
var wrappedContent = '<div class="md-toast-content">' + parsedTemplate.html() + '</div>'; | |||
var parsedTemplate = angular.element(template.replace(/<!--(.*?)-->/g, '')); |
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 doesn't work because Angular actually lets you apply directives as comments.
5b58b47
to
414bb6b
Compare
@jelbourn - But to get our actual target we need to get a element, which allows children. Can you please take a look at my new version? |
parsedTemplate.empty().append(wrappedContent); | ||
for (var i = 0; i < parsedTemplate.length; i++) { | ||
if (parsedTemplate[i].nodeType != Node.COMMENT_NODE) { | ||
parsedTemplate = parsedTemplate.eq(i); |
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.
Wouldn't this not work for a template like this?
<span>
An element
</span>
<span>
A sibling element
</span>
@jelbourn - I need one decision from you. What should we do if we got two silbings as roots. Should we pick the first node, which allows to have childs. Or should we always use |
I think a much more straightforward approach would be to change |
414bb6b
to
842b0ac
Compare
842b0ac
to
4afb004
Compare
@jelbourn - Now it works perfectly. It allows comments, it allows sibling elements, it allows normal |
LGTM |
Fixes #6259