AngularJS ng-repeat ng-selected选择框

时间:2014-08-27 11:59:58

标签: angularjs angularjs-ng-repeat

<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>

我有以上所述,我用来重复json列表,如果匹配,也选择一个值。这一切都有效,但是当我点击选择框时,会出现一个如下所示的空白值:

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

有没有办法摆脱这种情况,还是我完成了ng-repeat全部错误?

1 个答案:

答案 0 :(得分:3)

对于您正在做的事情,您可以使用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