zafirov zafirov - 9 months ago 40
AngularJS Question

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

After my get request i get

$scope.variables =;

my select is:

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

after that i have two input text fields

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

On button click i want to post wid

$, $scope.wid).then(function (response) {

My problem is that i dont get the object variable in wid.adapter. I gog the id.
How to modify my code to get the variable instead of id?

Answer Source

use the variable as the value not the id

and use the ng-option attribute on the select to bind it properly

<select name="varSelect" id="varSelect" ng-model="wid.adapter"
    ng-options=" for variable in variables">