Skip to content
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
matthiasg opened this issue Jul 17, 2015 · 9 comments
Closed

attrs defining properties that are not existent in 1.4 #12370

matthiasg opened this issue Jul 17, 2015 · 9 comments

Comments

@matthiasg
Copy link

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.

@gkalpak
Copy link
Member

gkalpak commented Jul 17, 2015

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.

@matthiasg
Copy link
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.

@caitp
Copy link
Contributor

caitp commented Jul 17, 2015

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.

@matthiasg
Copy link
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.

@gkalpak
Copy link
Member

gkalpak commented Jul 17, 2015

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 😃

@caitp
Copy link
Contributor

caitp commented Jul 17, 2015

yeah i'm pretty sure we never merged it

@caitp
Copy link
Contributor

caitp commented Jul 17, 2015

#12290 still open and waiting

@matthiasg matthiasg changed the title attrs defining properties that are not exitant in 1.4 attrs defining properties that are not existent in 1.4 Jul 23, 2015
@Narretz
Copy link
Contributor

Narretz commented Jul 23, 2015

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

@matthiasg
Copy link
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants