I build a dropdown directive, and it work with a different objects types, each object has own particular atributes, i need to get some particular field inside a ng-repat of my dropdown, now, it's fixed cityName, how i can change cityName for a variable, which stay on controller?
<div class="listCombo" ng-show="showDrop" ng-mouseleave="lostFocus()">
<table>
<tr ng-repeat="result in results" ng-click="selectItem(result)">
<td> {{result.cityName}} </td>
</tr>
</table>
</div>
For example, i need to get peopleName rather than cityName.
Yes it is possible to change the property attribute dynamically in
ng-repeat
.Below is a sample example code on how to achieve this.1) You should have data source like below to make things easy
2) In your HTML have something like this in your
ng-repeat
If you look at JS we have mentioned
$scope.objName = 'name';
i.e it will display all the names in a list,if we change the$scope.objName
to 'Age' then it will display corresponding ages in the data source.Hope this is answers your question.
If you want to show cityName or peopleName conditionally in td,
you can use like this.
It's not building DOM conditionally but you can see like that. Wheather it is not a good way on you, but I hope it to help you.