在Angularjs中选择绑定ng-model的对象
Angularjs select with ng-repeat, on select bind ng-model with object
在我的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>
相关文章:
- 从 Javascript 中设置 ng-model name
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- Angularjs:ng重复对象数组
- 对象不能在angularjs ng-model中访问
- ng-repeat不绑定ng-model对象数组
- 如果值为空,ng-model 将从对象中删除元素
- 当 ng-model 和 ng-options 引用不同的对象时,如何使用 ng-init 在选择框中选择默认值
- Angular将解析对象传递给Ng-Model
- 在Angularjs中选择绑定ng-model的对象
- “[对象对象]“;而不是Object被传递给ng-model用于
- 使用ng-model选择下拉框中的两个对象
- 从不同的对象分配ng-model输入值
- 显式控制ng-model对象的顺序
- ng-model对象的Angular问题
- 如何将ng-model添加到运行时创建的html对象中
- 给ng-model指定一个select对象
- ng-model将JavaScript对象属性设置为array
- 在ng-value和ng-model(Angularjs)中映射对象
- AngularJS - $scope对象中缺少ng-model项