Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I need to display this values of an property inside an json object with ng-repeat.

"id_products" : [5730827476402176: 2, 5173045979250688: 1, 5735995932672000: 2]

I am using ng-repeat on <tr> inside a table. If the property is a simple array I can display without problems but as the object showed above I am just getting [].

This is a snippet of my code:

<tbody>
        <tr class="animate-repeat" ng-repeat="item in sales|orderBy: 'name'|filter: filter">
          
          <th> {{item.id_products}}</th>
          
          .....

I tried nested ng-repeats but I get the same result.

What is the right way to display this object?

Thanks.

share|improve this question
    
Have you tried running a ng-repeat inside the ng-repeat on the item and then say "value in item"? – McBoman Aug 20 '16 at 14:51
    
yes. it is the same thing – Dan Romulus Aug 20 '16 at 14:51
    
Can I get you to create a fiddler or something the we can try? – McBoman Aug 20 '16 at 14:54
    
ok. just a few minutes... – Dan Romulus Aug 20 '16 at 14:54
1  
The code you posted ([5730827476402176: 2, 5173045979250688: 1, 5735995932672000: 2]) is not valid JavaScript. – JB Nizet Aug 20 '16 at 15:07

see the ng-repeat documentation - "The built-in filters orderBy and filter do not work with objects, and will throw an error if used with one.

If you are hitting any of these limitations, the recommended workaround is to convert your object into an array that is sorted into the order that you prefer before providing it to ngRepeat"

https://docs.angularjs.org/api/ng/directive/ngRepeat

share|improve this answer
    
I didn't tried to use the built in filter but just display it. Anyway I think this type of structure is not allowed because I try to iterate it and display in the console with angular.forEach loop and it is not displaying anything. – Dan Romulus Aug 20 '16 at 16:40

This object data structure is not javascript or json valid.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.