【问题标题】:ng-selected not working for angular 1.6.1, but works for 1.3.15ng-selected 不适用于 angular 1.6.1,但适用于 1.3.15
【发布时间】:2017-08-02 01:17:13
【问题描述】:

以下选择在 Angular 1.3.15 中的 2 处预选了正确的 option,但在 Angular 1.6.1 中没有:

Selected is {{myNumber}}
<select ng-model="myNumber">
    <option ng-selected="i == myNumber" ng-repeat="i in [1,2,3]">
        {{i}}
    </option>
</select>

然后在 JS 中:

$scope.myNumber = 2;

在 Angular 1.6.1 中,下拉菜单如下所示:

如何在 Angular 1.6.1 中执行此操作?

【问题讨论】:

  • 尝试考虑ng-options

标签: javascript html angularjs select


【解决方案1】:

文档中提到过,github上也有同样的问题,

[bug] ngSelected won't select the option within a ngRepeat

或者你应该使用ng-options

<select ng-model="user.item_id" ng-options="i.id as i.name for i in items">
</select> 

【讨论】:

  • 无赖。 “as”、“for”和“in”语法总是让我对 ng-options 感到困惑。
  • 以上答案有帮助吗
猜你喜欢
  • 1970-01-01
  • 2021-01-11
  • 1970-01-01
  • 1970-01-01
  • 2016-11-05
  • 1970-01-01
  • 2018-07-29
  • 1970-01-01
  • 2015-01-04
相关资源
最近更新 更多