I am making a form where the user can add more fields by clicking the add button yet. for this I use ng-repeat, and when the user clicks the "Add more" button, one field is placed in the array in the results of ng-repeat in another field.
Now, for some cases, the ng-repeat array may contain some fields, I want to make them read-only, but if the user clicks the Add More button, then this field may be editable. My code is:
HTML code
<div ng-repeat="field in ui_fields">
<label for="Language">Field Name :</label><input class="form-control" type="text" ng-model="field.name">
<label for="Language">Field type :</label>
<select class="form-control" ng-model="field.type">
<option value="">Select field type</option>
<option value="timedate">Date & Time</option>
<option value="text">Text</option>
</select>
</div>
Angular code
$scope.add_extra_field = function(){
$scope.ui_fields.push({
name: "",
type: ""
});
}
source
share