admin管理员组文章数量:1403352
I'll start off with mentioning I'm very new to Angular so I'm probably not doing things in the correct "Angular way".
I have the following ng-repeat looping through some data - the correct data is being returned.
<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>
For some reason the ng-value on the input="text" fields doesn't show. I need to pass through the data from the field in to the updateAttribute() function, which is why I'm binding the model to the attr variable that I'm passing through. This variable is then being used for an API call.
If I take the model off the text fields I have the correct values, but I need someone of getting that value and passing it through to the function.
If there is another way that I should be doing this please let me know :)
I'll start off with mentioning I'm very new to Angular so I'm probably not doing things in the correct "Angular way".
I have the following ng-repeat looping through some data - the correct data is being returned.
<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>
For some reason the ng-value on the input="text" fields doesn't show. I need to pass through the data from the field in to the updateAttribute() function, which is why I'm binding the model to the attr variable that I'm passing through. This variable is then being used for an API call.
If I take the model off the text fields I have the correct values, but I need someone of getting that value and passing it through to the function.
If there is another way that I should be doing this please let me know :)
Share Improve this question edited Jun 24, 2014 at 10:28 AndrewPolland 3,0714 gold badges30 silver badges39 bronze badges asked Jun 24, 2014 at 10:22 user3770721user3770721 231 silver badge3 bronze badges1 Answer
Reset to default 5Ng-value is not ment for intput[text]
Binds the given expression to the value of input[select] or input[radio], so that when the element is selected, the ngModel of that element is set to the bound value.
See docs
Additionally ng-change expects expression so you do not have to use {{}}
use this instead
ng-change="updateAttribute(attr,attribute)"
本文标签: javascriptAngularjsngmodel overwrite my ngvalue on textinputStack Overflow
版权声明:本文标题:javascript - Angular.js - ng-model overwrite my ng-value on text-input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744410984a2604949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论