Angularjs选择ng-repeat,选择绑定ng-model with object

时间:2016-10-26 19:01:59

标签: javascript angularjs

我收到请求后,我

$scope.variables = response.data;

我的选择是:

<select name="varSelect" id="varSelect" ng-model="wid.adapter">
            <option ng-repeat="variable in variables" value="{{variable.id}}">{{variable.name}}</option>
</select>

之后我有两个输入文本字段

<input type="text" ng-model="wid.url" />
<input type="text" ng-model="wid.name" />

点击按钮,我想发布wid

$http.post(some_url, $scope.wid).then(function (response) {
            console.log(response);
});

我的问题是我没有在wid.adapter中获取对象变量。我gog id。 如何修改我的代码来获取变量而不是id?

1 个答案:

答案 0 :(得分:3)

使用variable作为值而不是id

并使用select上的ng-option属性将其正确绑定

<select name="varSelect" id="varSelect" ng-model="wid.adapter"
    ng-options="variable.name for variable in variables">
    </select>
相关问题