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

Truely empty objects in ngRepeat #1944

Closed
spacenick opened this issue Feb 3, 2013 · 3 comments
Closed

Truely empty objects in ngRepeat #1944

spacenick opened this issue Feb 3, 2013 · 3 comments

Comments

@spacenick
Copy link

Let's say I have a pseudo-hashmap built using Object.create(null) and I want to ng-repeat over it.
This is breaking :

<div ng-repeat="(key,value) in myHashmap"></div>

Because obviously my hashMap doesn't inherit the Object prototype and thus doesn't have the hasOwnProperty method.

Can be quickly fixed by changing the size function

if (!ownPropsOnly || Object.hasOwnProperty.call(obj,key))

and the ngRepeatDirective

if (Object.hasOwnProperty.call(collection,key) && key.charAt(0) != '$') {

However I'd love to have some feedbacks from the team if this is actually on purpose. Thanks!

@mernen
Copy link
Contributor

mernen commented Mar 5, 2013

Huh, I wasn't aware of Object.create(null) until now!

But your proposed change seems like a good idea to me in general, as it also shields AngularJS against objects that define hasOwnProperty.

@spacenick
Copy link
Author

Awesome @mernen

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants