【问题标题】:AngularJS - Select dropdown not showingAngularJS - 选择下拉菜单不显示
【发布时间】:2016-10-27 01:52:20
【问题描述】:

我正在处理我的第一个 AngularJS 项目,但我的选择有问题。选项已填充,如果我关注选择,我可以使用键盘向上/向下箭头来更改选择的选项。但是,下拉菜单本身从未出现,我不知道为什么。如果这有什么不同,我也在使用 Bootstrap。

JS代码:

$http({
  method: 'GET',
  url: 'api/Mortality/GetMortalityReasonsList',
  headers: {
    'Authorization': 'Bearer ' + $localStorage.token,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  }
}).then(function (success) {
  $scope.reasons = success.data;
}, function (error) {
  debugger;
});

HTML 代码:

<div class="form-group">
    <label for="reason">Reason</label>
    <select class="form-control" id="reason" ng-model="log.reason" ng-options="reason as reason.Name for reason in reasons track by reason.Id"></select>
</div>

回复:

[
   {
      "Id": 638,
      "Name": "Adjusted Deaths",
      "Code": "11",
      "CultureCode": "en-US"
   },
   ...
]

编辑:该字段本身已正确填充。我只是没有下拉菜单。我猜这是某种 CSS 问题,但不确定为什么它不起作用。即使我使用硬编码列表填充列表而不是进行网络调用,也会出现此问题。

【问题讨论】:

  • 发布您的 json 响应
  • 调用 apply 有影响吗? $scope.reasons = success.data; $scope.$apply();
  • 添加了响应。当我添加 $scope.$apply() 它说 $digest 已经在进行中。
  • 除非您遇到某种类型的错误,否则这是不可能的。我创建了一个plnkr here,它似乎工作正常。我在 Angular 之前包含了 bootstrap 和 jquery。但没关系,它总是显示下拉菜单。您确定吗,您的控制台没有任何错误。

标签: javascript angularjs twitter-bootstrap


【解决方案1】:
  <select class="form-control" id="reason" ng-model="reason" ng-options="reason as reason.Name for reason in optionsdownload"></select>

DEMO

【讨论】:

    【解决方案2】:

    显然 Angular 的材料设计库和 Bootstrap 不能很好地结合在一起。删除了 MD 库,它又开始正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多