我收到请求后,我
$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?
答案 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>