【问题标题】:ng2-select2 disable default valueng2-select2 禁用默认值
【发布时间】:2020-01-24 22:41:30
【问题描述】:

我的 Angular 项目中有以下设置:

Hello.component.html

<select2
 ngDefaultControl
 [data]="list"
 [options]="{ placeholder: placeholder }"
>
</select2>

Hello.component.ts

list = [
{
  id: 1,
  text: 'Item 1 one'
},
{
  id: 2,
  text: 'Item 2 one'
},
{
  id: 3,
  text: 'Item 3 one'
},
{
  id: 4,
  text: 'Item 4 one'
},
{
  id: 5,
  text: 'Item 5 one'
}]

当我的组件加载时,默认情况下会自动选择“list”数组中的第一个值。如何更改默认选择值?

【问题讨论】:

    标签: angular jquery-select2


    【解决方案1】:

    来自ng2-select2 GitHub Repo

    value 字符串:选择 2 的默认值

    演示示例:

    <select2 [data]="exampleData" [value]="startValue" (valueChanged)="changed($event)"></select2>
    

    或者在你的情况下:

    <select2
     ngDefaultControl
     [data]="list"
     [options]="{ placeholder: placeholder }"
     [value]="list[1]"
    >
    </select2>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 2017-01-16
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      相关资源
      最近更新 更多