【发布时间】:2021-04-20 11:18:48
【问题描述】:
您好,SonarQube 出现以下错误 “订阅”已弃用。使用观察者而不是完整的回调。 我在 Angular 9 中正式使用。 感谢您的帮助和时间
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 正在弹出此消息 “订阅”已弃用。使用观察者而不是完整的回调
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);
}
},
});
},
},
【问题讨论】:
-
也许你需要添加 "next": func with depricaded 方法? .subscribe({ next: this.handleUpdateResponse.bind(this), error: this.handleError.bind(this) });
-
@PhilippMeissner 对我来说听起来并不令人困惑。任何指南将不胜感激:)
-
@snoopy 听起来很混乱,还是提供的示例根本不起作用?如果是这样,您到底尝试了什么? (将代码 + 错误添加到您的问题中)。
标签: javascript angular angular-formly