您好,我在使用SonarQube时遇到了以下错误:
'subscribe'已弃用。请使用观察者而不是完整的回调函数。我正在使用Angular 9中的Formly。
感谢您的帮助和时间。
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);
}
});
},
},
请查看更新的代码,但是SonarQube仍然弹出此消息:“'subscribe'已弃用。使用观察者替代完整回调函数”。
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);
}
},
});
},
},