Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

attrs defining properties that are not existent in 1.4 #12370

Closed

Description

@matthiasg

in <=1.3 the directives attrs object only contained those attributes that are actually defined on an element. with 1.4 the attrs contains them even when they are not defined (seems to me it looks in scope or so, but havent looked into that).

previously we could write if(attrs.myAttr){} now we have to check for undefined.

Activity

  1. gkalpak commented on Jul 17, 2015

    @gkalpak
    Member

    Writing if (attrs.myAttr) isn't enough, because it does an empty string still evaluates to false (i.e. the attribute may be present but you won't detect it using if (attrs.myAttr) if it has an empty value.
    So, if you were using if (attrs.myAttr) then setting non-present properties to undefined does not affect your usecase.

    A more consistent way to check for whether an attribute is present or not, is if (attrs.hasOwnProperty('myAttr')) (and this would indeed be affected by the new behaviour you described).

    Anyway, I think this issue has been fixed recently, so could you try if it still happens on 1.4.3 ?
    If it does, it would be better to post a live demo, so people can identify (and solve) the problem sooner.

  2. matthiasg commented on Jul 17, 2015

    @matthiasg
    Author

    Sorry we also used ownproperty but thanks I will restest

    -----Original Message-----
    From: "Georgios Kalpakas" notifications@github.com
    Sent: ‎17.‎07.‎2015 19:48
    To: "angular/angular.js" angular.js@noreply.github.com
    Cc: "matthiasg" mgt576@gmail.com
    Subject: Re: [angular.js] attrs defining properties that are not exitant in1.4 (#12370)

    Writing if (attrs.myAttr) isn't enough, because it does an empty string still evaluates to false (i.e. the attribute may be present but you won't detect it using if (attrs.myAttr) if it has an empty value.
    So, if you were using if (attrs.myAttr) then setting non-present properties to undefined does not affect your usecase.
    A more consistent way to check for whether an attribute is present or not, is if (attrs.hasOwnProperty('myAttr')) (and this would indeed be affected by the new behaviour you described).
    Anyway, I think this issue has been fixed recently, so could you try if it still happens on 1.4.3 ?
    If it does, it would be better to post a live demo, so people can identify (and solve) the problem sooner.
    —
    Reply to this email directly or view it on GitHub.

  3. caitp commented on Jul 17, 2015

    @caitp
    Contributor

    if (attrs.hasOwnProperty('myAttr')) this isn't super good, because there are cases where the attribute is shadowed but uninitialized. You also want to tack a && attrs.myAttr !== void 0 test, for reliability.

    IIRC this is fixed (at least marginally) in one of my recent prs, but I don't think it's landed yet.

  4. matthiasg commented on Jul 17, 2015

    @matthiasg
    Author

    Thanks ! Will keep an eye out.

    -----Original Message-----
    From: "⭐caitp⭐" notifications@github.com
    Sent: ‎17.‎07.‎2015 19:57
    To: "angular/angular.js" angular.js@noreply.github.com
    Cc: "matthiasg" mgt576@gmail.com
    Subject: Re: [angular.js] attrs defining properties that are not exitant in1.4 (#12370)

    if (attrs.hasOwnProperty('myAttr')) this isn't super good, because there are cases where the attribute is shadowed but uninitialized. You also want to tack a && attrs.myAttr !== void 0 test, for reliability.
    IIRC this is fixed (at least marginally) in one of my recent prs, but I don't think it's landed yet.
    —
    Reply to this email directly or view it on GitHub.

  5. gkalpak commented on Jul 17, 2015

    @gkalpak
    Member

    It used to work (without the void 0 part), but then it broke and the it was fixed, but then the fix was reverted again (because it broke ngMaterial) and then I thought it was fixed again (by @caitp's PR), but I am not 100% sure it has been merged. Fun stuff 😃

  6. caitp commented on Jul 17, 2015

    @caitp
    Contributor

    yeah i'm pretty sure we never merged it

  7. caitp commented on Jul 17, 2015

    @caitp
    Contributor

    #12290 still open and waiting

  8. changed the title [-]attrs defining properties that are not exitant in 1.4[/-] [+]attrs defining properties that are not existent in 1.4[/+] on Jul 23, 2015
  9. Narretz commented on Jul 23, 2015

    @Narretz
    Contributor

    I am gonna close this as a duplicate. I am pretty confident #12290 will land this or next week.

  10. matthiasg commented on Jul 29, 2015

    @matthiasg
    Author

    our workaround right now is

    function hasAttr(element, attributeName){
      return element.filter(`[${attributeName}]`).length > 0;
    }
    

    PS: without es6 we would write filter('['+attributeName+']') of course

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