0
subjectname: Object0: "Math"1: "Science"2: "Chem"

I have an object user and user.subjectname looks as above:

Now, I need to loop through values in the object and print in my table using angular js. How do I go about it?

To create user.subjectname, I had used

<input type="text" ng-model="user.subjectname[$index]">

as I am dynamically creating input row, so this is inside of ng-repeat .

If I use {{ user.studentname }}, I get {"0":"vhj","1":"tyuh"} in my table, however, I want to retrieve values from this.

console.log(user) gives this structure:

enter image description here

1
  • user.subjectname.Object0 have you tried ? Or share some more code to understand better. Paste your json response may help Commented Jul 11, 2015 at 12:50

1 Answer 1

0

To loop through the keys/values in user.subjectname and print out the values you would do this:

<span ng-repeat="(key, val) in user.subjectname">
  {{val}}
</span>

This is assuming that your object looks like this:

var user = { subjectname: { 0: 'Math', 1: 'Science', 2: 'Chem' } };

I hope you don't mind me asking, but have you exposed user on $scope?


jsBin

Sign up to request clarification or add additional context in comments.

5 Comments

I had expected same but though it prints out object using console.log, while trying to access it in <td> of table, nothing is printed.
I'm going to assume that your object looks like this. `user = {subjectname: { 0: 'Math', 1: 'Science', 2: 'Chem' }}; In which case it should work just fine. The description of your object in the question posted, is somewhat hard to interpret.
I have tried to explain it further, could you please check?
Yes, Yes, I have exposed it to $scope.
Please check the jsBin I supplied to my original answer. Modify it to your liking, but I'm quite certain it should be working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.