Search code examples
angularjsangularjs-scopeng-optionsangularjs-ng-options

AngularJS ng-options


I have this select in AngularJS:

<select id="objectId" name="seccionId" class="form-control" ng-model="arguments.seccion" data-ng-options="item.id as item.valor for item in arguments.objects" required></select>

I like to save both values in scope, but I only save one value.

Any form to save both values?

Thanks!!!


Solution

  • If you want the entire value to be bound to ng-model than you can simply omit the select portion of your ng-options expression.

    In this case, it's the item.id part.

    data-ng-options="item.valor for item in arguments.objects"
    

    This will ensure the entire item is bound to your ng-model when selecting.