Javascript 以angularjs和ng repeat生成的形式使用插值范围字段名
我需要使用ng repeat生成一个表单。范围变量的名称,我希望输入的结果被定位,我作为参数之一给出,所以它必须被插值 用于调整的Plunker位于。 下面是形式的定义Javascript 以angularjs和ng repeat生成的形式使用插值范围字段名,javascript,angularjs,angularjs-directive,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Directive,Angularjs Ng Repeat,我需要使用ng repeat生成一个表单。范围变量的名称,我希望输入的结果被定位,我作为参数之一给出,所以它必须被插值 用于调整的Plunker位于。 下面是形式的定义 $scope.formFields = [ { id: "sample11", nextfree: 'rcv.UseNextFreeSampleId', ngmodel: 'rcv.SampleId', maxlen: 10, focus: false, u
$scope.formFields = [
{
id: "sample11",
nextfree: 'rcv.UseNextFreeSampleId',
ngmodel: 'rcv.SampleId',
maxlen: 10,
focus: false,
useNextFree: true,
useHint: true,
text: {status: "status must be shown"}
}
];
其中我指定$scope.rcv.SampleId应包含结果
HTML看起来像:
<input class="input-small form-control" ng-required="!{{field.nextfree}}" type='text'
id='field.id' ng-model='{{field.ngmodel}}'
ng-maxlength='field.maxlen' ng-disabled='{{field.nextfree}}>
<span class="input-group-addon" ng-show='field.useNextFree'>
<input type = "checkbox", ng-model='{{field.nextfree}}' ng-value = "true" >
<label>Use Option</label>
</span>
<span class="help-block small" ng-show='field.useHint'>{{field.text.status}}</span>
Angular不允许将插值用作ng模型
您可以通过稍微更改字段来实现所需的功能。nextfree:'UseNextFreeSampleId',ngmodel:'SampleId'
,然后将其作为$scope.rvc:ng model=“rcv[field.ngmodel]”的属性引用。