简体   繁体   English

如何为请求模型分配对象值

[英]How to assign object values to request model

im using mat tab.in this if vailid then retuens values.otherwise return null.and final object values assign to request object ..我使用 mat tab.in this if valid then retuens values.otherwise return null.and final object values分配给请求对象..

 saveSettings() {

            if (this.msmsForm.valid) {
                const smsSetting: MasterSMSSetting = {
                    SMSEnabled: this.msmsForm.get('allowOverRide').value,
                    AllowUserOverride: this.msmsForm.get('smsEnabled').value,
                    SMSURL: this.msmsForm.get('smsUrl').value,
                    SMSLogUrl: this.msmsForm.get('smsLogUrl').value,
                    ClientId: this.msmsForm.get('clientId').value,
                    AccesToken: this.msmsForm.get('accessToken').value
                };
            }
            if (this.memailForm.valid) {
            const emailsetting: MasterEmailSetting = {
                SEmailEnabled: this.memailForm.get('allowOverRide').value,
                AllowOverride: this.memailForm.get('emailEnabled').value,
                EmailUrl: this.memailForm.get('emailUrl').value,
                EmailLogUrl: this.memailForm.get('emailLogUrl').value,
                ClientId: this.memailForm.get('clientId').value,
                AccesToken: this.memailForm.get('accessToken').value
            };
        }
            const request: MasterSettingRequest = {
                masterSMS: smsSetting, // getting error "Cannot find name smsSetting'"
                masterEMail: emailsetting, //getting error "Cannot find name smsSetting"
                RequestType: this.requestType
            };


this.mastersettingservice.saveMasterSetting(request).subscribe((response: Response)

in this, I wrote if valid.im unable to get those object values due to closed if block!在此,我写了 if valid.im 由于关闭 if 块而无法获取这些对象值! please let know how to assign those values to a request object请让我们知道如何将这些值分配给请求对象

try to use global class variables same as requestType:尝试使用与 requestType 相同的全局类变量:

emailsetting: MasterEmailSetting;
smsSetting: MasterSMSSetting;

saveSettings() {
  if (this.msmsForm.valid) {
    this.smsSetting = {
      SMSEnabled: this.msmsForm.get('allowOverRide').value,
      AllowUserOverride: this.msmsForm.get('smsEnabled').value,
      SMSURL: this.msmsForm.get('smsUrl').value,
      SMSLogUrl: this.msmsForm.get('smsLogUrl').value,
      ClientId: this.msmsForm.get('clientId').value,
      AccesToken: this.msmsForm.get('accessToken').value
    };
  }
  if (this.memailForm.valid) {
    this.emailsetting = {
      SEmailEnabled: this.memailForm.get('allowOverRide').value,
      AllowOverride: this.memailForm.get('emailEnabled').value,
      EmailUrl: this.memailForm.get('emailUrl').value,
      EmailLogUrl: this.memailForm.get('emailLogUrl').value,
      ClientId: this.memailForm.get('clientId').value,
      AccesToken: this.memailForm.get('accessToken').value
    };
  }
  const request: MasterSettingRequest = {
    masterSMS: this.smsSetting,
    masterEMail: this.emailsetting,
    RequestType: this.requestType
  };
  this.mastersettingservice.saveMasterSetting(request).subscribe((response: Response)

You can get your solution from below code:您可以从以下代码获得解决方案:

saveSettings() {

        if (this.msmsForm.valid) {
            const smsSetting  = {
                SMSEnabled: this.msmsForm.get('allowOverRide').value,
                AllowUserOverride: this.msmsForm.get('smsEnabled').value,
                SMSURL: this.msmsForm.get('smsUrl').value,
                SMSLogUrl: this.msmsForm.get('smsLogUrl').value,
                ClientId: this.msmsForm.get('clientId').value,
                AccesToken: this.msmsForm.get('accessToken').value
            };
        }
        if (this.memailForm.valid) {
            const emailsetting = {
                SEmailEnabled: this.memailForm.get('allowOverRide').value,
                AllowOverride: this.memailForm.get('emailEnabled').value,
                EmailUrl: this.memailForm.get('emailUrl').value,
                EmailLogUrl: this.memailForm.get('emailLogUrl').value,
                ClientId: this.memailForm.get('clientId').value,
                AccesToken: this.memailForm.get('accessToken').value
            };
        }
        const request = {
                masterSMS: smsSetting, // getting error "Cannot find name smsSetting'"
                masterEMail: emailsetting, //getting error "Cannot find name smsSetting"
                RequestType: this.requestType
            };


            this.mastersettingservice.saveMasterSetting(request).subscribe((response: Response)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM