Angular选择中的默认文本

时间:2015-02-15 01:19:41

标签: angularjs ng-options angularjs-select

默认情况下,如果在<select>中未选择任何内容,则angular使用空值。如何将其更改为显示Please select one的文字?

2 个答案:

答案 0 :(得分:16)

您没有提供任何代码,因此我无法提供相对于您的代码的示例,但尝试添加一个选项元素,例如

<select ng-model="item" ng-options="item.category for item in items"
        ng-change="doSomething()">
    <option value="">Please select one</option>
</select>

答案 1 :(得分:2)

通过ng-selected属性:

<select>
  <option>Hello!</option>
  <option ng-selected="selected">Please select one</option>
  <option>Another option</option>
</select>

查看参考:https://docs.angularjs.org/api/ng/directive/ngSelected