我有关于 Angular 6 的项目。我的一些服务扩展了基类。基类是没有@Injectable
装饰器的常规 TypeScript 类。当我尝试运行应用程序时,出现错误:
NullInjectorError:没有 HttpCommonService 的提供者!
疯狂的猜测 - 也许它以某种方式与 DI 有关(因为我从另一个没有@Component
装饰器的基类中扩展了一些组件并且它工作得很好),但是,即使在 DI 的情况下,我也不会创建新的基类实例扩展服务等级。
问题是什么,或者至少,我应该在哪里搜索问题?
例子
这是基类:
export class HttpCommonService {
constructor(protected http: HttpClient) {}
/* Methods here */
}
这是注入到应用根目录的服务
@Injectable({ providedIn: 'root' })
export class HttpService extends HttpCommonService {
constructor(protected http: HttpClient) {
super(http);
}
/* Methods here */
}