【问题标题】:AngularJS Material dropdown options not workingAngularJS材质下拉选项不起作用
【发布时间】:2018-03-25 16:41:03
【问题描述】:

我正在尝试使用 AngularJS Material 构建一个表单,但在显示我的下拉选项时遇到了问题。我的 HTML 在下面,我的选项存储在我的服务器脚本上的对象数组中。我在下面做错了什么?

<md-input-container class="md-block" flex-gt-sm ng-switch-when="choice">
    <label for="{{element.section_element_name}}">{{element.section_element_label}}</label>
    <md-select id={ {element.section_element_name}} type="selectbasic" value={{element.q_value}}>
        <md-option ng-repeat="option in element.section_element_choices" value="{{option.element_choice_value}}">
            {{option.element_choice_label}}
        </md-option>
    </md-select>
</md-input-container>

【问题讨论】:

  • 您可以添加元素对象的示例吗?
  • 首先你应该在你的 md-select 标签中添加 ng-model="selectedItem"

标签: angularjs angularjs-material md-select


【解决方案1】:
<md-input-container class="md-block" flex-gt-sm ng-switch-when="choice">
  <label for="{{element.section_element_name}}">{{element.section_element_label}}</label>
  <md-select id={ {element.section_element_name}} type="selectbasic" ng-model="selectedItem">
    <md-option ng-repeat="option in element.section_element_choices" value="{{option.element_choice_value}}">
        {{option.element_choice_label}}
    </md-option>
</md-select>

【讨论】:

  • 哇,这就像一个魅力!抱歉,我对 Angular 很陌生,ng-model="selectedItem" 定义在哪里?只是想了解为什么会这样=)。谢谢!
  • ngModel 负责将视图绑定到模型中,其他指令如输入、文本区域或选择需要。在您的情况下,指令 md select 需要 ng-model。 docs.angularjs.org/api/ng/directive/ngModel
猜你喜欢
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-10
  • 2020-12-02
  • 2019-06-30
  • 1970-01-01
  • 2016-08-08
相关资源
最近更新 更多