2
我使用FormBuilder爲數據庫添加值。在Angular 2中的下拉列表中選擇的設置值
this.formUser = this._form.group({
"firstName": new FormControl('', [Validators.required]),
"lastName": new FormControl('', [Validators.required]),
"externalCompany": new FormControl('', [Validators.required])
})
將這些值加我想設置一個下拉列表(外部公司)的價值,珍惜,我事先
<select class="form-control" id="companyExternal" formControlName="externalCompany" (ngModelChange)=onChangeExternalC($event)>
<option value="" >Select existing company...</option>
<option value="{{company}}" *ngFor="let company of externalCompanies">{{company}}</option>
<option value="Company name..." >ADD ANOTHER...</option>
</select>
提交之前,我想這
this._commServe.addExternalCompany(company).subscribe((data) => {
this.formUser.value.externalCompany = company.CompanyName;
}, (error) => {
this.errorMessage = <any>error;
})
我也嘗試使用ngModel也沒有按預期工作。
將最好的辦法是設置此下拉列表中選擇狀態,而不訴諸的jQuery例如