Angularjs 如何在动态列表(包括索引)中使用ng if创建字段?

Angularjs 如何在动态列表(包括索引)中使用ng if创建字段?,angularjs,list,dynamic,field,Angularjs,List,Dynamic,Field,当选择“其他”选项时,我已经使用此方法一千次来创建“请描述”字段,但当它是动态列表的一部分时,它不起作用。添加索引的某些方面使它无法工作。如何在动态列表中执行此操作 通常,我会尝试以下其中一种: <div class="checkbox"> <label> <input type="checkbox" name="discrepancy_resolution_other_{{$index}}" ng-true-value="'Checked'

当选择“其他”选项时,我已经使用此方法一千次来创建“请描述”字段,但当它是动态列表的一部分时,它不起作用。添加索引的某些方面使它无法工作。如何在动态列表中执行此操作

通常,我会尝试以下其中一种:

<div class="checkbox">
    <label>
        <input type="checkbox" name="discrepancy_resolution_other_{{$index}}" ng-true-value="'Checked'" ng-false-value="'delete'"> Other
    </label>
    <label ng-if="model.discrepancy_resolution_other_{{$index}} === 'Checked'">
        <input type="text" name="discrepancy_resolution_other_content" placeholder="Please describe" required="true">
    </label>
</div>

<div class="checkbox">
    <label>
        <input type="checkbox" name="discrepancy_resolution_other_{{$index}}" ng-true-value="'Checked'" ng-false-value="'delete'"> Other
    </label>
    <label ng-if="model[discrepancy_resolution_other_{{$index}}] === 'Checked'">
        <input type="text" name="discrepancy_resolution_other_content_{{$index}}" placeholder="Please describe" required="true">
    </label>
</div>

其他
其他
这无法工作:

ng-if="model.discrepancy_resolution_other_{{$index}} === 'Checked'"
请记住,如果
ng if
(或
ng show
)表达式中不能使用插值。例如,如果您的变量名为
差异\u分辨率\u其他\u 3
,您可以通过以下方式解决问题:

ng-if="getThing(model, $index) === 'Checked'"
然后在控制器中实现获取:

$scope.getThing = function(model, index) {
  if (index === 3) {
    return model.discrepancy_resolution_other_3;
  }
  // etc...
}
但是,将变量放入数组
$scope.model.myArray
会更容易,因此您可以直接从HTML访问它:

ng-if="model.myArray[$index] === 'Checked'"

请包括代码,或者至少是你提到的“方法”。他包括了标记,我一直编辑它来修复它,但他一直用顶升标记覆盖我的编辑。