【问题标题】:StaticInjectorError(AppModule) window in angular 6角度为 6 的 StaticInjectorError(AppModule) 窗口
【发布时间】:2018-09-24 05:43:35
【问题描述】:

如何使用窗口从该位置打开excel文件?

constructor( private fb: FormBuilder, private http: Http, private router: Router,private window:Window) { }

window.open(this.excelURL + "report/" + this.getexportlist.data.data, '_blank');

它显示了下面提到的错误:

ERROR 错误:未捕获(承诺中):错误:StaticInjectorError(AppModule)[CouponUsageReportComponent -> Window]: StaticInjectorError(Platform: core)[CouponUsageReportComponent -> Window]: NullInjectorError: 没有 Window 的提供者!

【问题讨论】:

    标签: angular typescript2.0


    【解决方案1】:

    错误提示您使用了 window 但未在您的 module.ts Provider ex providers 中定义:[Window]

    在您的app.module.ts 的提供者下添加它

    【讨论】:

    • Windows 提供程序?
    • @RevathiVijay 是的,它的窗口。标记答案是否有帮助
    【解决方案2】:

    如果您使用 Window 对象作为依赖注入,那么您必须在某处提供它(最好是 AppModule 的提供程序数组),或者您可以在不注入的情况下使用它。

    【讨论】:

    • 是的,我在引发 StaticInjectorError 错误的模块中提供了WINDOW_PROVIDERS,并且它起作用了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-10-25
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多