In my HTML code, I have the following:
<mat-select placeholder="Job Category" formControlName="job_category"
(selectionChange)="selectedJobType($event)">
<mat-option *ngFor="let job of jobTypes" [value]="job.jobid">
{{ job.jobname }}
</mat-option>
</mat-select>
In my TypeScript file, I have defined a FormBuilder group for job category as such:
jobRegisterForm = this.fb.group({
job_category: [null, Validators.required]});
Inside the ngOnInit() function, I am setting the value using an ID like so:
this.jobRegisterForm.get('job_category').setValue(this.jobData.jobcategoryid);
After this, the value is displayed correctly in the dropdown. If the user changes the dropdown value, I can capture that information with the following TypeScript code:
selectedJobType(event: MatSelectChange) {
this.selectedMatJob = {
value: event.value,
text: event.source.triggerValue
};
}
However, if the user does not change the dropdown value and clicks on save, how do I retrieve the selected text and value for 'job_category'?