2

我将首先提到我对 Angular 很陌生,所以我可能没有以正确的“Angular 方式”做事。

我有以下 ng-repeat 循环遍历一些数据 - 正在返回正确的数据。

<tr ng-repeat="attribute in attributeCategory.attributes">
    <td>
        {{attribute.name}}
    </td>
    <td>
        <input type="checkbox" ng-model="attr.enabled" ng-checked="{{attribute.parameters.enabled}}" ng-change="updateAttribute(attr, {{attribute.attribute_id}})"/>
    </td>
    <td>
        <input type="checkbox" ng-model="attr.normalise" ng-checked="{{attribute.parameters.normalise}}" ng-change="updateAttribute(attr, {{attribute.attribute_id}})"/>
    </td>                
    <td>
        <input type="checkbox" ng-model="attr.reverse" ng-checked="{{attribute.parameters.reverse}}" ng-change="updateAttribute(attr, {{attribute.attribute_id}})"/>
    </td>
    <td>
        <input type="text" ng-model="attr.min_threshold" ng-value="{{attribute.parameters.min_threshold}}" ng-change="updateAttribute(attr, {{attribute.attribute_id}})"/>                    
    </td>
    <td>
        <input type="text" ng-model="attr.max_threshold" ng-value="{{attribute.parameters.max_threshold}}" ng-change="updateAttribute(attr, {{attribute.attribute_id}})"/>                    
    </td>
<tr>

由于某种原因, input="text" 字段上的 ng-value 没有显示。我需要将字段中的数据传递给 updateAttribute() 函数,这就是我将模型绑定到我正在传递的 attr 变量的原因。该变量随后被用于 API 调用。

如果我将模型从文本字段中取出,我将获得正确的值,但我需要有人获取该值并将其传递给函数。

如果有另一种方法我应该这样做,请告诉我:)

4

1 回答 1

5

Ng-value 不是输入的 [text]

将给定的表达式绑定到 input[select] 或 input[radio] 的值,以便在选择元素时,将该元素的 ngModel 设置为绑定值。

查看文档

此外 ng-change 需要表达式,因此您不必使用 {{}}

改用这个

ng-change="updateAttribute(attr,attribute)"
于 2014-06-24T11:35:41.767 回答