Checking for HTML5 File API Support in Angular?

落花浮王杯 提交于 2019-12-13 22:46:23

问题


When coding a check for HTML5 File API browser support like this:

  private hasHtml5FileApiSupport;
  constructor(@Optional() @Inject(DOCUMENT) document: Document) {
    const w = document.defaultView;
    this.hasHtml5FileApiSupport = w.File && w.FileReader && w.FileList && w.Blob;

VSCode draws red squigglies under the w.File && w.FileReader && w.FileList parts.

Is there a way to get rid of these / Is there a better way to do this?


回答1:


If we inject document using the Document type then we get the strict type checking, and VSCode draws squigglies, however if we use any instead of Document the errors disappear:

private hasHtml5FileApiSupport;
constructor(@Optional() @Inject(DOCUMENT) document: any) {
  const w = document.defaultView;
  this.hasHtml5FileApiSupport = w.File && w.FileReader && w.FileList && w.Blob;
}


来源:https://stackoverflow.com/questions/53292312/checking-for-html5-file-api-support-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!