My challenge is to connect a model called 'User' to a series of input fields. Since I don't know the specific fields in advance, I need to write generic code that dynamically sets up the form based on the available fields.
<script>
function MyController($scope){
$scope.fields = ['name','password','dob'];
$scope.user1 = {name:"Shahal",password:"secret"}
};
</script>
<div ng-app ng-controller="MyController">
<ul>
<li ng-repeat="field in fields">
<label>{{field}}</label><input type="text" ng-model="user1.{{field}}">
</li>
</ul>
<pre>{{fields}}</pre>
</div>
I'm attempting to iterate through the fields and display an input field for each one (from the scope). However, the binding is not functioning correctly as I'm trying to evaluate an expression inside ng-model.
The goal is to have three input fields (name, password, dob) with the user1 object connected to each respective field.
Check out the fiddle here
Any assistance would be appreciated!