ngplayground
ngplayground

Reputation: 21617

AngularJS ng-repeat ng-selected select box

<select class="input--select" ng-model="updatemember.client_company_id" ng-change="updatestreet()">
    <option ng-repeat="company in companies" ng-value="company.id" ng-selected="{{company.id == updatemember.client_company_id}}">{{ company.name }}</option>
</select>

I have the above that I'm using to repeat a json list and also choose a value if it matches up. This all work but when I click on the select box there is a blank value that looks like this:

<option value="? string:2 ?"></option>

Is there any way to get rid of this or have I done the ng-repeat all wrong?

Upvotes: 1

Views: 312

Answers (1)

Malkus
Malkus

Reputation: 3726

For what you are doing you can use ng-options.

<select class="input--select" 
    ng-model="updatemember.client_company_id" ng-change="updatestreet()"
    ng-options="company.id as company.name for company in companies">
</select>

Working Fiddle

Upvotes: 3

Related Questions