0
我想在我的Angular2应用程序中使用Select2。当我选择选项时,我可以打印出我的选择,但遇到了将选定选项绑定到角度表单控件的问题。Angular2 - 使用Select2多选择时绑定到formControl
这是我的html:
<select id="fields" class="form-control fields-select" multiple="multiple"
formControlName="branchCode">
<option *ngFor="let field of _availableFields" [value]="field">{{field}}
</option>
</select>
这是我的TS文件:
private _availableFields: Array<any> = ['Value1', 'Value2', 'Value3'];
private _selectedFields: Array<string> = [];
export class AppComponent{
editForm : new FormGroup({
email: new FormControl('', Validators.required),
branchCode: new FormControl('', Validators.required),
});
}
ngAfterViewInit(){
jQuery('.fields-select').select2();
jQuery('.fields-select').on('change',
(e) =>
this._selectedFields = jQuery(e.target).val();
console.log(this._selectedFields);
);
};
我得到了我的变种this._selectedFields选择。 我怎样才能将我选择的this._selectedFields中的值绑定到formControl'branchCode'?