为什么 angular-js ng-option 没有显示为选中状态?

Why the angular-js ng-option not showing as selected?

<select ng-model="field.value" class="form-control" ng-attr-name="{{name}}">
            <option selected="selected">{{field.fieldName}}</option>
            <option ng-repeat="app in field.attributes.split(',')" value="{{app}}">{{app}}</option>
</select>

在此代码中,我预期的行为是,它将显示 select 框,并且它 select 我添加的第一个选项 selected="selected"。

但它不是 select 那个 "selected" 属性元素。

我也用 ng-selected="true" 试过了。这对我也没有帮助。对我有什么建议吗?

您应该使用 ngOptions 指令 - 而不是 option 元素上的 ngRepeat

<select ng-model="field.value" ng-options="app as app for app in field.attributes.split(',')" class="form-control" ng-attr-name="{{name}}"></select>

现在只需将 ngModel (field.value) 设置为您要选择的字段。