在Angular2中安装FileReaderSync [英] Installing FileReaderSync in Angular2

查看:54
本文介绍了在Angular2中安装FileReaderSync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Angular2中安装 FileReaderSync ?

How do I install FileReaderSync in Angular2?

它出现在文件 node_modules/typescript/lib/lib.webworker.d.ts 中,但不能使用.

It appears in the file node_modules/typescript/lib/lib.webworker.d.ts but not can use it.

FileReader 我可以使用它而无需导入任何内容.

The FileReader I can use it without having to import anything.

我需要对FileReaderSync做些不同的事情吗?

I need to do something different with FileReaderSync?

错误TS2304:找不到名称'FileReaderSync'.

推荐答案

几个月前,我遇到了同样的问题,解决方案是编写自定义类型.

I had the same issue few months ago, the solution was to write custom typings.

main.bowser.d.ts

main.bowser.d.ts

interface FileReaderSync {
  readAsArrayBuffer(blob: Blob): any;
  readAsBinaryString(blob: Blob): void;
  readAsDataURL(blob: Blob): string;
  readAsText(blob: Blob, encoding?: string): string;
}

declare var FileReaderSync: {
  prototype: FileReaderSync;
  new(): FileReaderSync;
};

并在引导angular2时包括它们

and include them when you bootstrap angular2

// <reference path="./main.browser.d.ts" />

我刚才写了一篇关于这个的文章:D http://icode.co/angular2/php/2016/12/21/async-file-streaming-from-JS-to-PHP-WebWorkers.html

I wrote an article about this just now :D http://icode.co/angular2/php/2016/12/21/async-file-streaming-from-JS-to-PHP-WebWorkers.html

这篇关于在Angular2中安装FileReaderSync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆