0

I have a variable param in scope as $scope.param that is always either foo or bar. I'm creating a table with rows defined by <tr ng-repeat="d in data">.

When I have the following: <td>{{d.foo}}</td> or <td>{{d.bar}}</td> everything works and the data shows up fine. However, when I have <td>{{d.param}}</td> angular can't find anything and the cell is blank.

In other words, I'm trying to access an object value using a variable as the key rather than the key itself. Any idea how to do this?

1
  • $scope.param and @scope.data are not the same thing. Just put param and not d.param. Commented Mar 18, 2014 at 19:34

1 Answer 1

2

Use bracket notation:

{{d[param]}}
Sign up to request clarification or add additional context in comments.

Comments

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.