I have an array of objects ($scope.fields
) that define how input fields should be set up for the $scope.data
object model. The fieldName property is actually the path in the data
Object to the field. Nested objects are separated by a period mark.
eg:
$scope.data = {
user: {
}
}
$scope.fields = [
{fieldName:'user.firstName',fieldLabel:'First Name',dsiabled:false}
{fieldName:'user.location.lat',fieldLabel:'Latitude',dsiabled:false}
{fieldName:'user.location.long',fieldLabel:'Latitude',dsiabled:false}
]
What is the best way in the HTML to bind the $scope.data fields based on the fieldName. I am aware of javascript eval - but is that the best way to do it ? And why does this syntax not work for me ?
ie:
<div ng-repeat="fieldObj in fields">
<dd ng-bind="eval('data.' fieldObj.fieldName)"></dd>
</div>
ng-bind
. – Mikiso