Jan Kowalski Jan Kowalski - 15 days ago 8
AngularJS Question

How to concat 2 expressions in interpolate

I have directive where I want to render a list from various objects.

Controller:

$scope.propertyName = 'price';


View:

<div ng-repeat="item in obj">
<a>{{ 'item.' + propertyName }}</a>
</div>


Objects
obj
will have various properties and I can't use static property name.

{{ 'item.' + propertyName }}
return string
'item.price'
- I want expression like
{{ item.price }}
.

Answer

Just like you would do in JavaScript:

{{ item[propertyName] }}