【发布时间】:2017-01-06 14:00:19
【问题描述】:
我有抽象类(没有构造函数),我想注入另一个类。
抽象类:
import { ErrorHandler } from '../../shared/services/errorHandler.service';
import { Inject } from '@angular/core';
export abstract class BaseApiComponent<T> {
@Inject(ErrorHandler) errorHandler: ErrorHandler;
this.errorHandler.test();
}
注入类:
import { Injectable } from '@angular/core';
@Injectable()
export class ErrorHandler {
constructor() { }
public test() {
console.log('Test');
}
}
我还有下一个错误
ORIGINAL EXCEPTION: TypeError: Cannot read property 'test' of undefined
我该如何解决这个问题?
【问题讨论】:
标签: angular typescript dependency-injection abstract-class