在Angularjs中选择绑定ng-model的对象

Angularjs select with ng-repeat, on select bind ng-model with object

本文关键字:ng-model 对象 绑定 选择 Angularjs      更新时间:2023-09-26

在我的get请求后,我得到

$scope.variables = response.data;

my select is:

<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" />

On button点击i want to post wid

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

我的问题是,我没有得到对象变量在宽。适配器。我明白了。如何修改我的代码,以获得变量而不是id?

使用variable作为值,而不是id

,并在select上使用ng-option属性来正确绑定

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