Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'subscribe' is deprecated. Use an observer instead of a complete callback

Hi am having the following error with SonarQube 'subscribe' is deprecated. Use an observer instead of a complete callback. Am using formly in angular 9. Thank you for your help and time

              onInit: (field: UiFormFieldConfig) => {
                const CostsControl = FormUtil.getControl(field.form, ContactDetailsFieldKey.Costs);
                CostsControl?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((Cost: string) => {
                  if (Cost) {
                    const costsToSet = !Codes ? null : Cost;
                    field?.formControl?.setValue(costsToSet);
                  }
                });
              },
            },

Please find updated code and yet sonarQube is popping this message 'subscribe' is deprecated. Use an observer instead of a complete callback

  hooks: {
              onInit: (field: UiFormFieldConfig) => {
                const CostsControl = FormUtil.getControl(field.form, ContactDetailsFieldKey.Costs);
                CostsControl ?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe({
                  next: (Cost: string) => {
                    if (Cost) {
                      const costsToSet = !Codes ? null : Cost;
                      field?.formControl?.setValue(costsToSet);
                    }
                  },
                });
              },
            },
like image 704
snoopy Avatar asked Dec 22 '25 17:12

snoopy


1 Answers

Based on the answer @Philipp Meissner mentioned, you should simple do:

CostsControl?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe(
    next: (Cost: string) => {
        if (Cost) {
            const costsToSet = !Codes ? null : Cost;
            field?.formControl?.setValue(costsToSet);
        }
    },
    error: () => { // log error }
});
like image 194
iamdlm Avatar answered Dec 24 '25 08:12

iamdlm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!