使字段只读取角度

n.i*_*imp 4 javascript angularjs

我正在创建一个表单,用户可以通过单击添加更多按钮添加更多字段.因为我正在使用ng-repeat,当用户点击添加更多按钮时,一个字段被推送到ng-repeat结果中的数组到另一个字段.

现在,对于某些情况,ng-repeat数组可能包含一些字段,我想让它们只读,但如果用户点击添加更多按钮,那么该字段可以编辑.我的代码:

HTML代码

 <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>
Run Code Online (Sandbox Code Playgroud)

角度代码

$scope.add_extra_field = function(){
    $scope.ui_fields.push({ 
        name: "",
        type: ""
      });
    }
Run Code Online (Sandbox Code Playgroud)

whe*_*ell 5

isreadonlyui_fields数组和ngReadOnly指令中使用额外的字段,如:

你的HTML:

<div ng-repeat="field in ui_fields">
    <label for="Language">Field Name :</label><input class="form-control" ng-readonly="field.isreadonly" type="text" ng-model="field.name">
    <label for="Language">Field type :</label>
    <select class="form-control"  ng-disabled="field.isreadonly" ng-model="field.type">
        <option value="">Select field type</option>
        <option value="timedate">Date & Time</option>
        <option value="text">Text</option>
    </select>
</div>
Run Code Online (Sandbox Code Playgroud)

你的javascript:

$scope.add_extra_field = function(){
    $scope.ui_fields.push({ 
        name: "",
        type: "",
        isreadonly: false
      });
    }
Run Code Online (Sandbox Code Playgroud)