Skip to content

Warn when using boolean attributes in directives #5955

Closed

Description

@matthieusieben

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.

Activity

  1. zoechi commented on Dec 16, 2015

    @zoechi
    Contributor

    See also this ongoing discussion about boolean attributes #5761

  2. matthieusieben commented on Dec 17, 2015

    @matthieusieben
    Author

    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.

  3. pkozlowski-opensource commented on Aug 30, 2016

    @pkozlowski-opensource
    Member

    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.

  4. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions