ng-class in ng-repeat with a $index 选择器

ng-class in ng-repeat with a $index selector

我想 select 在 ng-class 表单元素中,它在 ng-repeat 里面,我需要一个 1:n select 或者在ng-class。但是 {{}} + $index 在 ng-class 表达式中工作正常。扇区解析正确。但是 ng-class 无法处理它。它没有检测到 select 或者,当 {{}} + $index 在里面时。

代码:

<form name="vm.itemForm" ng-submit="vm.onSave()">
(...)
  <tr ng-repeat="item in vm.item.sizes | orderBy:predicate:reverse">
    (...)
     <div class="dc-input-group">
        <input class=""
               ng-model="item.stock"
               ng-class="{ 'testclass': vm.itemform.{{'stockInput'+$index}}.mySelector  }" 
               name="{{'stockInput'+$index}}" />
        </div>

HTML 输出:

  <input class="form-validation dc-input dc-input--in-input-group dc-input--text-right ng-touched ng-not-empty ng-dirty ng-valid-number ng-valid ng-valid-required" 
    ng-model="item.stock"
    ng-class="{ 'testclass': vm.form.stockInput1.$valid }" 
    required=""
    name="stockInput1" 
    type="number"> 

ng-class 已经是一个表达式,因此您将 2 个表达式放在彼此中。您可以这样修复它:

<input class=""
       ng-model="item.stock"
       ng-class="{'testclass': vm.itemform['stockInput'+$index].mySelector}" 
       name="{{'stockInput'+$index}}" />