Angular 表单生成器 - 根据所选 select 值 属性 设置值
Angular Form Builder - set value based on chosen select value property
这是我的 Angular Form Builder 初始化组:
contactReason: this.formBuilder.group({
description: '',
source: this.sourceType()
})
我有一个 select 预定义值 'description' 这些可以是许多不同的值,例如"request for information" 这是我的应用程序中其他地方使用的映射示例:
public ContactReason = {
"request for information": 'incoming',
"other incoming": 'incoming',
"call update": 'outgoing',
"information provided": 'outgoing',
"attempted contact": 'outgoing',
"regular contact": 'outgoing',
"other outgoing": 'outgoing',
};
如您所见,每个描述都分配给 "incoming or outgoing"。
我想创建一个方法来进行此映射,这样当他们 select 描述时,它将 "incoming or outgoing" 映射到此处...
source: this.sourceType()
private sourceType() {
//logic for source mapping based on description.value
}
如果您对上述方法有任何帮助,我们将不胜感激。谢谢
我通过使用映射值数组按照我提出问题的方式将其映射。相当直接,但会留作参考。
public logEntryContactReason = {
"request for information": 'incoming',
"other incoming": 'incoming',
"case update": 'outgoing',
"information provided": 'outgoing',
"attempted contact": 'outgoing',
"regular contact": 'outgoing',
"other outgoing": 'outgoing',
};
private sourceType() {
const data = this.contactForm.value;
return this.logEntryContactReason[data.contactReason.description]
}
这是我的 Angular Form Builder 初始化组:
contactReason: this.formBuilder.group({
description: '',
source: this.sourceType()
})
我有一个 select 预定义值 'description' 这些可以是许多不同的值,例如"request for information" 这是我的应用程序中其他地方使用的映射示例:
public ContactReason = {
"request for information": 'incoming',
"other incoming": 'incoming',
"call update": 'outgoing',
"information provided": 'outgoing',
"attempted contact": 'outgoing',
"regular contact": 'outgoing',
"other outgoing": 'outgoing',
};
如您所见,每个描述都分配给 "incoming or outgoing"。
我想创建一个方法来进行此映射,这样当他们 select 描述时,它将 "incoming or outgoing" 映射到此处...
source: this.sourceType()
private sourceType() {
//logic for source mapping based on description.value
}
如果您对上述方法有任何帮助,我们将不胜感激。谢谢
我通过使用映射值数组按照我提出问题的方式将其映射。相当直接,但会留作参考。
public logEntryContactReason = {
"request for information": 'incoming',
"other incoming": 'incoming',
"case update": 'outgoing',
"information provided": 'outgoing',
"attempted contact": 'outgoing',
"regular contact": 'outgoing',
"other outgoing": 'outgoing',
};
private sourceType() {
const data = this.contactForm.value;
return this.logEntryContactReason[data.contactReason.description]
}