未定义角度类型脚本依赖项或未定义类

时间:2019-06-11 13:38:54

标签: angular typescript dependency-injection

我想在扩展抽象类的可注入对象中注入可注入对象。但是要么我的依赖项未定义,要么类本身未定义。在添加stepRouter之前,该类运行良好,因此我认为这是某个类在某个地方存在的问题。

我首先遇到一个问题,即我的依赖项未定义并且在https://github.com/angular/angular/issues/5155上绊倒,看到我也必须将类归类为super。但是当调用super时,类本身未定义。

注意:我从类中删除了所有内容,只保留了所有构造方法和装饰方法

错误:ReferenceError:未定义InstallationWizard

我要使用的课程。

如果我从此类中删除构造函数,则错误消失了,但所有属性均未定义。

@Injectable()
export class InstallationWizard extends Wizard {
    constructor(
        protected storage: Storage,
        protected toaster: Toaster,
        protected projectApi: ProjectApi,
        protected formApi: FormApi,
        public stepRouter: InstallationStepRouter
    ) {
        super(storage, toaster, projectApi, formApi, stepRouter)
    }
}

抽象的向导类

export abstract class Wizard {
    constructor(
        protected storage: Storage,
        protected toaster: Toaster,
        protected projectApi: ProjectApi,
        protected formApi: FormApi,
        public stepRouter: StepRouter
    ) {
        this.pictures = new Array<PictureInterface>();
    }
}

安装步骤路由器

@Injectable()
export class InstallationStepRouter extends StepRouter {

}

它正在扩展的抽象类

export abstract class StepRouter {
}

1 个答案:

答案 0 :(得分:0)

使用@ angular / core注入器

@Injectable()
export class InstallationWizard extends Wizard {
    constructor(
        protected injector: Injector
    ) {
        super(injector)
    }
}

export abstract class Wizard {
    protected stepRouter: StepRouter;

    constructor(injector: Injector
    ) {
        this.stepRouter = this.injector.get(StepRouter);
    }
}