【问题标题】:AngularJS Material: Cannot get value of md-selectAngularJS 材料:无法获取 md-select 的值
【发布时间】:2019-11-10 03:07:10
【问题描述】:

我有一个 AngularJS 材质选择:

       <md-input-container style="margin-right: 10px;">
            <label>Roll</label>
            <md-select id="acc-type" required="" ng-model="rolle">
                <md-option ng-selected="true" value="Tenant">Tenant</md-option>
                <md-option value="Lessor">Lessor</md-option>
            </md-select>
        </md-input-container>

我想获得实际选择的选项。我试过了

    var e = document.getElementById("acc-type");
    var selectedItem = e.value;

但我收到的都是未定义的。是否有任何选项可以在 AngularJS 中获取 md-select 的值?

【问题讨论】:

    标签: angularjs drop-down-menu angularjs-material


    【解决方案1】:

    由于您已经在md-select 中定义了ng-model="rolle",您可以通过$scope.rolle 访问它

    试试:

    var selectedItem = $scope.rolle
    

    【讨论】:

    【解决方案2】:

    它的角度 Js 和模型已经分配,​​所以尝试 试试

     console.log($scope.rolle);
    

    【讨论】:

    • 非常感谢。我不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多