Search code examples
angularjsangularjs-ng-options

Is it possible to concatenate values in Angular ng-options


Basically, I'm trying to populate a select box but concatenate values from the first_name column and last_name column.

What I want to do (doesn't work):

<select ng-model="buyers" ng-options="b.id as (b.first_name + " " + b.last_name) for b in buyers"></select>

What does work:

<select ng-model="buyers" ng-options="b.id as b.first_name for b in buyers"></select>

Solution

  • The quotes are important. It won't work with double quotes inside double quotes or single quotes inside single quotes.

    What does work:

    <select ng-model="buyers" ng-options='b.id as (b.first_name + " " + b.last_name) for b in buyers'></select>