-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Transcluded content is not trimmed #15077
Comments
O Dne 31. 8. 2016 16:16 napsal uživatel "Jenna Smith" <
|
This is how the DOM works. Whitespace and linebreaks create text nodes that contain only whitespace. I guess it's unlikely that someone wants the current behavior, but iwe cannot say 100% that it isn't so. If you minfied your html you won't have this problem. But we have to think about if there's a better way to handle this. |
@Narretz: I do minify my HTML in production. However, during development everything appears broken so I'm having to avoid this approach. I know how the DOM works, however, it seems strange that a project would require that a whitespace only transclude overrides the fallback. Of course, you can't say 100% that the current behaviour isn't what's wanted but what if the percentage it's wanted is a lot less than the percentage it isn't. It seems to render this fallback thing quite useless. If we're concerned about keeping the way it behaves and not breaking existing code that might depend on current behaviour, could we make it optional somehow? |
OK, so I think we should probably support trimming if the content is only whitespace. |
Unfortunately as this would be a breaking change, we can't do it in 1.5.9. It will be in 1.6. But you can alway patch your version of 1.5.x to get the required behaviour until you upgrade to 1.6. |
If the transcluded content is only whitespace then we should use the fallback content instead. This allows more flexibility in formatting your HTML. Closes angular#15077 BREAKING CHANGE: Previously whitespace only transclusion would be treated as the transclusion being "not empty", which meant that fallback content was not used in that case. Now if you only provide whitespace as the transclusion content, it will be assumed to be empty and the fallback content will be used instead. If you really do want whitespace then you can force it to be used by adding a comment to the whitespace.
When specifying an
ng-transclude
element, the documentation says you can provide a fallback that will render if no content is transcluded. However, if there is only whitespace in the transclusion slot it will replace the fallback with this whitespace.I prefer to markup my components as follows:
Doing it this way means it always passes some whitespace as the transcluded content and my fallback is removed. To fix I have to change the markup to:
It doesn't seem right that the position of the closing tag changes how the component renders.
I'm using Angular 1.5.5.
The text was updated successfully, but these errors were encountered: