You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warn when using boolean attributes in directives #5955
I created a custom directive which defined the use of the open attribute. I didn't know at the time that open is an html5 boolean attribute. So when my partial got minified, the open attribute's value disappeared and it took me a while to figure out why.
I know this occurred because of my poor knowledge of HTML5 but I bet I'm not the only one that will encounter this kind of issue. It would be handy is angular had the (optional) functionality to display a warning when a native HTML boolean attribute is used in or as a directive.
Note that in angular 2 [attr.foo]="expr" in an html file will probably not be minified by a tool such as html-minifier. I am talking here about Angular 1.x in which a directive/component would either have the name or a binding to an html 5 boolean attribute.
Since element attributes in Angular 1.x are not wrapped inside any brackets, if a developer uses a boolean attribute in a directive, the presence of this attribute in the HTML markup may be interpreted both by Angular and the browser itself, resulting in an unpredictable behavior.
Now I know that developers should prefix their directives and that they are supposed to know the HTML specifications. But not all of us are perfect (who even knows about the open attribute!?) and being able to see a warning may help.
Note that I am just trying to open a discussion here. The best solution may simply be kangax/html-minifier#448.
the presence of this attribute in the HTML markup may be interpreted both by Angular and the browser itself, resulting in an unpredictable behavior.
This is not the case as a directive will "capture" a given property binding.
Note that I am just trying to open a discussion here. The best solution may simply be kangax/html-minifier#448.
I would say so. I don't think HTML minifiers should strip attributes like this. There are many legitimate cases where we want to have Boolean attributes so having a warning would be confusing for Angular users.
Activity
zoechi commentedon Dec 16, 2015
See also this ongoing discussion about boolean attributes #5761
matthieusieben commentedon Dec 17, 2015
Note that in angular 2
[attr.foo]="expr"in an html file will probably not be minified by a tool such as html-minifier. I am talking here about Angular 1.x in which a directive/component would either have the name or a binding to an html 5 boolean attribute.Since element attributes in Angular 1.x are not wrapped inside any brackets, if a developer uses a boolean attribute in a directive, the presence of this attribute in the HTML markup may be interpreted both by Angular and the browser itself, resulting in an unpredictable behavior.
Now I know that developers should prefix their directives and that they are supposed to know the HTML specifications. But not all of us are perfect (who even knows about the
openattribute!?) and being able to see a warning may help.Note that I am just trying to open a discussion here. The best solution may simply be kangax/html-minifier#448.
pkozlowski-opensource commentedon Aug 30, 2016
This is not the case as a directive will "capture" a given property binding.
I would say so. I don't think HTML minifiers should strip attributes like this. There are many legitimate cases where we want to have Boolean attributes so having a warning would be confusing for Angular users.
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.