将服务传递给抽象类的构造函数

时间:2019-12-01 11:20:07

标签: angular typescript static abstract-class

我试图创建一个全局帮助器类,该类将轻松访问我的方法(例如Global.OnShowSuccess(...,...),但是在包含服务时会出现问题。

这是我尝试过的:

import { ToastrService } from "ngx-toastr";

export abstract class Global {


    private static _toastr: ToastrService;


    constructor(private toastr: ToastrService) {
        Global._toastr = this.toastr;
    }

    public static OnShowError(header: string, message: string) {
        Global._toastr.error(message, header);
    }

    public static OnShowSuccess(header: string, message: string) {
        Global._toastr.success(message, header);
    }
}

Global._toastrundefined。我该如何解决?

0 个答案:

没有答案
相关问题