Is there a way to dynamically add a form control once the user has made a selection?
This is my select function:
selected(event: MatAutocompleteSelectedEvent): void {
this.setTechnologies = new Set();
this.setTechnologies.add(this.techInput.nativeElement.value);
}
Integrating a new controller
this.primaryFormGroup.addControl('tech', new FormControl('', []));
this.primaryFormGroup.valueChanges.subscribe(inputFields => {
if (inputFields) {
inputFields.tech = Array.from(this.setTechnologies);
}
}
The issue I'm facing is that the line
inputFields.tech = Array.from(this.setTechnologies);
gets executed, prior to the execution of the selected()
function. Consequently, the value of inputFields.tech
always remains empty.
How can I ensure that the function runs first?