【问题标题】:Angular2 - Adding new item to Select2 (ng2-select2)Angular2 - 将新项目添加到 Select2 (ng2-select2)
【发布时间】:2017-03-20 09:38:59
【问题描述】:

我在我的 Angular2 项目中使用 ng2-select2,如果它不在列表中(只有 一个 项目),我想创建新项目并将其存储在我的 component.ts 中以使用它我的 submitForm 稍后。看来我需要使用tokenizertokenSeparators 但是如何?

这是我的html代码:

<select2 [data]="generals" (valueChanged)="generalChanged($event)"></select2>

这是我的 component.ts 的最小化版本:

export class ProductComponent implements OnInit {
  public options: Select2Options;
  public generals: Array<Select2OptionData>;
  productForm: FormGroup;
  ngOnInit() {

    this.generals = [
        { id: '1', text: 'Red' }, { id: '2', text: 'Blue' }
    ];
  }

  generalChanged(data: { value: string }) {
    const control = this.productForm.controls['general'];
    control.setValue(data.value);
  }
}

【问题讨论】:

    标签: angular select2


    【解决方案1】:

    select2Options: 任意 = { 主题:“引导”, 标签: [] };

    将标签:[] 添加到 select2Options

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2023-04-01
      • 2017-08-04
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 2013-05-01
      相关资源
      最近更新 更多