Currently, I am utilizing FormBuilder in order to input values into a database.
this.formUser = this._form.group({
"firstName": new FormControl('', [Validators.required]),
"lastName": new FormControl('', [Validators.required]),
"externalCompany": new FormControl('', [Validators.required])
})
Prior to adding these values, I have a requirement to set the dropdown (external company) to a specific value that was previously submitted.
<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>
I experimented with the following approach:
this._commServe.addExternalCompany(company).subscribe((data) => {
this.formUser.value.externalCompany = company.CompanyName;
}, (error) => {
this.errorMessage = <any>error;
})
I also attempted to utilize ngModel, but this did not provide the desired outcome.
What would be the most effective method to establish the selected state of this dropdown without relying on jQuery, for instance?