【问题标题】:How to programmatically set a value to md-select如何以编程方式将值设置为 md-select
【发布时间】:2017-01-09 03:04:25
【问题描述】:

我正在关注 docmd-select 初始值设置。但我想通过按钮以编程方式设置md-select 的值。

这是我到目前为止所做的DEMO

【问题讨论】:

    标签: angularjs angular-material md-select


    【解决方案1】:

    md-select 期望对象值存在于selectedUser 中,而filter 确实返回过滤对象的数组。您应该通过对过滤结果执行[0] 来分配过滤数组的第一个元素。

    $scope.selectedUser = $scope.users.filter(function(user) {
         return user.id == id;
    })[0];
    

    Forked Codepen

    【讨论】:

    • 没想到这么简单
    猜你喜欢
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 2018-03-19
    相关资源
    最近更新 更多