【问题标题】:how to select default value of ui select?如何选择ui select的默认值?
【发布时间】:2016-12-31 17:24:20
【问题描述】:

您能告诉我如何在 UI -select 中设置默认值吗? 这是我的代码 http://plnkr.co/edit/tCrEM4oC9iMSYZffbEAX?p=preview 我希望 "Adrian" 应该默认选择。您能告诉我如何在模型示例 (21) 中设置 Adrian 年龄的默认值吗?

<ui-select tagging tagging-label="new tag" multiple ng-model="model.multipleDemo" theme="select2" ng-disabled="disabled" style="width: 300px;">
    <ui-select-match placeholder="Select colors...">{{$item.name}}</ui-select-match>
    <ui-select-choices repeat="color.age as color in people | filter:$select.search">
      {{color.name}}
    </ui-select-choices>
</ui-select>
<p>Selected: {{model.multipleDemo}}</p>

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-scope angular-ui-bootstrap angular-ui


    【解决方案1】:

    给你:http://plnkr.co/edit/0AAniDzf7fdKywh4Rfk5?p=preview

    在这种情况下你不能使用年龄,否则它会找到所有具有相同年龄的人,并最终使用最后一个。您需要一个唯一的 id,或者使用名称,就像我在我的 plunker 上所做的那样

    $scope.model.multipleDemo.push('Adrian');

    在选择时,我将重复更改为repeat="color.name as color in people | filter:$select.search"

    如果您改用年龄,会发生以下情况:http://plnkr.co/edit/i6usxawmcnxYuqmH58kw?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多