【发布时间】:2017-03-20 09:38:59
【问题描述】:
我在我的 Angular2 项目中使用 ng2-select2,如果它不在列表中(只有 一个 项目),我想创建新项目并将其存储在我的 component.ts 中以使用它我的 submitForm 稍后。看来我需要使用tokenizer 或tokenSeparators 但是如何?
这是我的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);
}
}
【问题讨论】: