2017-04-10 23 views
1

單擊按鈕後,我正在更改選擇框的值。我用模型驅動方法編寫了整個表單。選擇框位於子窗體組中。如何使用Angular2模型驅動表單設置子表單組的值?

this.profileForm = this.fb.group({ 

    name: this.fb.control('',[ Validators.required, Validators.minLength(3) ]), 
    website: this.fb.control('',[Validators.pattern('^(http|https|ftp)?(://)?(www|ftp)?.?[a-z0-9-]+(.|:)([a-z0-9-]+)+([/?].*)?$')]), 
    contributor: this.fb.control('',[Validators.email]), 
    dealershipLevel: this.fb.control('single',[ Validators.required ]), 
    manufacturer: this.fb.control('',[ Validators.required ]), 

    address : this.fb.group({ 
     addressline: this.fb.control('',[ Validators.required ]), 
     city: this.fb.control('',[ Validators.required ]), 
     state: this.fb.control('',[ Validators.required ]), 
     zip: this.fb.control('',[ Validators.required ]) 

    }) 
}) 

我想設置一旦按鈕被點擊的狀態選擇框中的值。有可能使用的代碼

this.profileForm.controls.manufacturer.setValue('Tvm', { onlySelf: true });

如何從子窗體集團控制設定的值來設置父窗體組的值?

回答

1
this.profileForm.get('address.state').setValue('Tvm', { onlySelf: true }); 
0

試試這個:

this.profileForm.patchValue({address:{state:'Tvm'}}, { onlySelf: true }); 
相關問題