0

I've two json as follows:

 users= [
        {
          "id": 0,
          "isActive": true,
          "age": 30,
          "name": "Hester Nunez",
          "dob": "10/12/2015",
          "email": "[email protected]",
          "phone": "+1 (975) 580-3067",
          "address": "918 Greenpoint Avenue, Elbert, Idaho, 7423"
        },
        {
          "id": 1,
          "isActive": false,
          "age": 23,
          "name": "Hopkins Cantu",
          "gender": "male",
          "dob": "16/02/2011",
          "email": "[email protected]",
          "phone": "+1 (966) 514-3562",
          "address": "332 Aurelia Court, Wright, New Mexico, 1481"
        }]


columns = [

        {
            "id": "column1",
            "key": "name",
            "title": "Name"
        },
        {
            "id": "column2",
            "key": "age",
            "title": "Age"
        },
        {
            "id": "column3",
            "key": "gender",
            "title": "Gender"
        },
        {
            "id": "column4",
            "key": "email",
            "title": "Email"
        },
        {
            "id": "column5",
            "key": "address",
            "title": "Address"
        }
    ]

To create a table of users I want to display the value of users based on the key of the column. Something like this:

<tr data-ng-repeat="user in users">
     <td data-ng-repeat="column in columns">{{user.{{column.key}}}}</td>
</tr>

As expected I'm getting the following parse error:

Error: [$parse:syntax] Syntax Error: Token '{' is not a valid identifier at column 6 of the expression [user.{{column.key] starting at [{{column.key].

Any suggestions on how to evaluate this nested expression?

1
  • use {{user[column.key]}} Commented Mar 3, 2016 at 10:09

1 Answer 1

4

Try this one :

<tr data-ng-repeat="user in users">
     <td data-ng-repeat="column in columns">{{user[column.key]}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

2 Comments

@ManojPaul, please do accept my answer if it helps you... :)
Please wait for 10 mins. SO is not allowing me to accept answer before 10 mins since I posted my question. :)

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.