【问题标题】:Default text in Angular selectAngular 选择中的默认文本
【发布时间】:2015-02-15 01:19:40
【问题描述】:

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

【问题讨论】:

    标签: angularjs ng-options angularjs-select


    【解决方案1】:

    您没有提供任何代码,因此我无法给出与您的代码相关的示例,但请尝试添加选项元素,例如

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

    【讨论】:

    • 补充一点:拥有 value="" 很重要。如果只是省略 value 属性,它将不起作用。
    【解决方案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

    【讨论】:

      猜你喜欢
      • 2012-11-13
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      相关资源
      最近更新 更多