【问题标题】:How set defaulte value for <select> with angular ng-repeat option? [duplicate]如何使用角度 ng-repeat 选项设置 <select> 的默认值? [复制]
【发布时间】:2018-07-04 20:31:09
【问题描述】:

我尝试为此下拉菜单设置默认值,但这并没有按我的预期工作,我不明白为什么?

<select ng-change="onChange()" ng-model="selectedInfo">
        <option value="" selected>Default</option>
        <option ng-repeat="(index, info) in infos" value="{{index}}">{{info.name}}</option>
</select>

我需要有 index 数字的价值,因为角度控制器中使用了。

我现在拥有的是

点击我有

在我选择其中之一后,我只有 3 个选项

我该如何解决?

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    我解决了

    <select ng-change="onChange()" ng-model="selectedInfo" ng-init="selectedInfo = infos[0]">
            <option value="" [selected]="0">Default</option>
            <option ng-repeat="(index, info) in infos" value="{{index}}">{{info.name}}</option>
    </select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 2020-03-26
      • 2020-07-12
      • 2015-02-21
      • 1970-01-01
      • 2016-12-11
      • 2015-07-17
      相关资源
      最近更新 更多