My approach to Angular Form Builder initialization includes a group that looks like this:
contactReason: this.formBuilder.group({
description: '',
source: this.sourceType()
})
For the 'description' field, I have a select option with predefined values such as "request for information". Here's a sample mapping I use in other parts of my application:
public ContactReason = {
"request for information": 'incoming',
"other incoming": 'incoming',
"call update": 'outgoing',
"information provided": 'outgoing',
"attempted contact": 'outgoing',
"regular contact": 'outgoing',
"other outgoing": 'outgoing',
};
Each description is associated with either "incoming" or "outgoing". A method is needed to map the selected description to the corresponding value here...
source: this.sourceType()
private sourceType() {
//logic for source mapping based on description.value
}
If you have any insights on how to implement the above method, your help would be greatly appreciated. Thank you!