0

I have a large table of data and a select field in each <td>. When selecting a value in that select field, I want to POST that value and an additional array to the server. Unfortunately, the additional array is being ignored by Angular:

<td>
    <input type="hidden" ng-model="compatibility.attributes" ng-value="[x.id, y.id]">
    <select ng-change="addCompatibility(compatibility)"
            ng-model="compatibility.rating"
            ng-options="rating.name for rating in ratings">
        <option value="">Rate</option>
    </select>
</td>

Both x.id and y.id are being resolved correctly. But they're not being included in the compatibility object when sending my request. Instead, only compatibility.rating is being filled.

2
  • Can you share the code for addCompatability? Commented Sep 16, 2014 at 11:41
  • So far it's only: $scope.addCompatibility = function(c) {console.log(c);}) where the only value c holds is rating. Commented Sep 16, 2014 at 11:44

1 Answer 1

1

Please see here http://jsbin.com/kewopu/1/edit

Use ng-init instead of ng-value

 <input type="hidden" ng-model="compatibility.attributes" ng-init="compatibility.attributes=[x.id, y.id]" >
    <select ng-change="addCompatibility(compatibility)"
            ng-model="compatibility.rating"
            ng-options="rating.name for rating in ratings">
        <option value="">Rate</option>
    </select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.