2016-12-06 36 views
0

我有以下代碼添加控件在OnInit方法。設置值,以形成控制初始化不工作angular2

this.form = new FormGroup({}); 
    this.form.addControl('select', new FormControl('')); 

添加控件後我不能設置值來控制;

this.form.controls['select'].SetValue() 

但其引發異常未定義

+0

您是否嘗試過在你的類構造函數初始化'FormGroup'?不確定你的要求是什麼。 – Drew13

回答

0

有你在使用的formGroupget方法檢查一樣選擇:

this.form.get('select').setValue('');