我想覆盖来自其他模块的服务,但出现错误“不是函数”
在我的组件(模块 1)中,我注入了服务
public constructor(private chartProgressService: ChartProgressService) {
}
在模块 2 中,我覆盖了提供程序中的服务
providers: [
{
provide: Configuration,
useClass: AppConfiguration,
},
{
provide: ChartProgressService,
useValue: MyChartProgressService
},
{
provide: LOCALE_ID,
useValue: 'de-DE',
}
],
这是 MyChartProgressService
import {Injectable} from '@angular/core';
@Injectable()
export class InnogyChartProgressService {
public getUnit(): string {
return '';
}
public getValue(currentValue: number, maxValue: number): number {
return currentValue;
}
}
在我的组件中调用 this.chartProgressService.getValue() 返回错误
HeaderComponent.html:11 ERROR TypeError: this.chartProgressService.getUnit is not a function
at ChartProgressComponent.ngOnInit (chart-progress.component.ts:33)
at checkAndUpdateDirectiveInline (core.js:12369)
at checkAndUpdateNodeInline (core.js:13893)
at checkAndUpdateNode (core.js:13836)
at debugCheckAndUpdateNode (core.js:14729)
at debugCheckDirectivesFn (core.js:14670)
at Object.eval [as updateDirectives] (HeaderComponent.html:11)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)
at checkAndUpdateView (core.js:13802)
at callViewAction (core.js:14153)
我想我需要你的帮助!谢谢!