-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Directive with 'replace: true' and template duplicates classes in the attrs parameter of the link fn #8159
Comments
If this is not what you want, you need to manually remove the merged class. There is currently no way around this. Technically So, just to sum up, this is basically doing what it's expected to do, even if it's inconvenient, and we probably can't change it in 1.x (this will be totally different in 2.0.0). But you can work around this by manually adjusting attributes. @IgorMinar is this a WONTFIX or do you think it would make sense to make some changes to this? As a classic example of the problems with merging attributes, SVG will often throw when we do that, so maybe we should offer some way to avoid merging. I am not really expecting us to, but I can see how it would be useful. |
@caitp, @jstrength is referring to the fact that the "center-block" class is repeated twice on the class attribute, where it should only be there once. |
@jeffbcross I understood that, it's a byproduct of the way our attribute merging works. If we detect that the attribute is there, we append to it with a preceding space. So, if the attribute is both in the directive template and the calling template, it shows up twice. There are a lot of other silly things that happen because of this (There was one where using I think this is just one of those silly things with repeat: true. We can't really do much about it unless it's okay to make huge breaking changes. and there is a limit to how much we can actually do about it (eg, replacing |
#6979 #6239, there are probably more of these open (including this one), but there are too many to go through right now while I make dinner! I can't recall the number or title of the one I'm thinking of, but yeah this is basically the main issue people run into with |
I've made a plunker to validate it still exists in 1.3.0 and it does. I will create a PR in a lil bit. |
@jstrength seems like the element itself doesn't have the duplicate classes ( also according the element.classList ). The duplicates only show up in the console. |
It wasn't manifesting itself in my application in any way that I could tell. Just something I came across when I was debugging my code and thought it should be fixed. |
Although it shouldn't really affect much (and More specifically, in mergeTemplateAttributes(), we are first merging the source attributes with the destination attributes, joining values if both have the same key. Right after that we are copying the keys in source that are not present in destination, but for some reason we are special-casing |
So this only duplicates the attributes internally. It'll probably be an easy fix, but without much impact. |
Exactly. I'm putting this in the backlog, but since |
Fixes angular#8159 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597
Fixes angular#8159 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597 Closes angular#5597
In replace directives, attribute values from the template are added twice to the replaced element when both the replaced element and the template element have the attribute. This does not affect the DOM, as it normalizes duplicate values. The values are however duplicated in the $attrs object that is available to directive link functions. Fixes angular#8159 Closes angular#14737
In replace directives, attribute values from the template are added twice to the replaced element when both the replaced element and the template element have the attribute. This does not affect the DOM, as it normalizes duplicate values. The values are however duplicated in the $attrs object that is available to directive link functions. Fixes #8159 Closes #14737
When I create a directive with a template that has a class attribute and
replace: true
. The attrs parameter in the link function duplicates the classes. They are also duplicated when I look at the element in the HTML.This appears to only happen when the tag that the directive is replacing also has a class attribute.
Here is some example code, along with the output I see in the console.
The text was updated successfully, but these errors were encountered: