Angular 8. Issue with Select box selected value

Hello All,

I recently started working in Angular8. I have a Model

export class Company{
id: number;
company_name: String;

constructor(id, company_name){
    this.id = id;
    this.company_name = company_name;
}

}

I am fetching the value of companies and storing it in the data member.
companiesDataset:Company=;

To generate the Select box. I am using

<select formControlName=“company_id” [ngClass]="{‘is-invalid’: experianceFormSubmitted && eF.company_id.errors }">
Select Company

                <option *ngFor="let companyData of companiesDataset" ngValue="{{ companyData }}">{{ companyData.company_name }}</option>

The Form builder and all the components are in place. When I try to open the form in edit mode. All the values are in place but the select box value is not get selected.

this.experianceForm.get(‘company_id’).setValue( userExperienceData.company );
this.experianceForm.get(‘job_title’).setValue( userExperienceData.job_title );
this.experianceForm.get(‘description’).setValue(userExperienceData.description );
this.experianceForm.get(‘start_date’).setValue( userExperienceData.start_date );
this.experianceForm.get(‘end_date’).setValue( userExperienceData.end_date );
this.experianceForm.get(‘still_working’).setValue( userExperienceData.still_working );
this.experianceForm.get(‘package’).setValue( userExperienceData.package );
this.experianceForm.get(‘designation’).setValue( userExperienceData.designation );

I am using select box in another component with a number array and it’s working as intended. But I am facing issue only with the model.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.