I have 3 drop downs on a page (which are loaded from an API call) and I need to call a different API service from one DD on the selectionChange event in which I use the value from the DD to bring back the model/data I need in order to populate/set an input field. The Angular code captures the value which I need and when calling the API service, the service is not being called (.NET API in debug mode).
For testing purposes, I've removed the forkJoin and used only 1 dropdown and it works (.NET API service is called in debug mode), but when I introduce the other drop downs with the forkJoin, it doesn't work. Not sure why, any help is much appreciated. I've also added it to the ForkJoin and if I make it a drop down for testing purposes, it works with no problems.
<mat-form-field fxFlex="30">
<mat-select formControlName="column1" placeholder="column1" (selectionChange)="onChange($event)" >
<mat-option>Clear</mat-option>
<mat-option *ngFor="let column1 of column1$ | async[value]="column1._id">{{ column1.title }}</mat-option>
</mat-select>
<mat-error*ngIf="submissionStatusForm.get('column1').hasError('required')">column1 is<strong>required</strong></mat-error>
</mat-form-field>
<mat-form-field fxFlex="30">
<input matInput placeholder="Column2" formControlName="column1" />
</mat-form-field>
export class AddTestComponent1 implements OnInit {
headers: string[];
submissionStatusForm: FormGroup;
matcher = new FormErrorStateMatcher();
isUpdateOperation: boolean;
isSubmited: boolean;
control: AbstractControl;
column1$: any;
column2: any;
column3: any;
column4: any;
constructor(
@Inject(MAT_DIALOG_DATA) data,
private fb: FormBuilder,
private activatedRoute: ActivatedRoute,
private dialog: MatDialog,
private dialogRef: MatDialogRef<AddTestComponent1>,
private utilityService: UtilityService,
private localStorageService: LocalStorageService,
private apiService: ApiService,
public userAccessService: UserAccessService
)
{
this.submissionStatusForm = this.fb.group({
column1: fb.control(null,
{validators: [Validators.required],
updateOn: 'blur',
}),
column2: fb.control(null
),
column3: fb.control(null,
{validators: [Validators.required],
updateOn: 'blur',
}),
column4: fb.control(null,
{validators: [Validators.required],
updateOn: 'blur',
}),
});
this.loadDropDowns();
}
}
loadDropDowns()
{
this.column1$ = this.apiService.getAll(this.headers,API_NAME_COLUMN_1);
forkJoin(
this.apiService.getAll(this.headers, API_NAME_COLUMN_3),
this.apiService.getAll(this.headers, API_NAME_COLUMN_4)
).subscribe(([column3, column4]) => {
this.column3 = column3;
this.column4 = column4;
}, (error) => this.error_handle(`Unable to load data`));
}
onChange(args)
{
const data: any = {
Id_1: args.value,
Id_2: 1
};
this.column2 = this.apiService.getName(this.headers, API_NAME, data);
this.submissionStatusForm.patchValue({'column2':this.column2.label});
}
Expected results should be the text needed from the web service, but the API service is not being called. I've Inspected the code and can't seem to see any error messages, but will continue to debug and investigate. Thanks for your help on this.