【发布时间】:2020-01-12 21:37:00
【问题描述】:
` src/app/app.component.ts(20,27) 中的错误:错误 TS2345:'string | 类型的参数ArrayBuffer' 不可分配给“字符串”类型的参数。 类型 'ArrayBuffer' 不能分配给类型 'string'。
import { Component } from '@angular/core';
declare const fileSelected: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
binaryStr :any;
inputObj :any;
fileSelected(inputObj){
var fileObj = this.inputObj.files[0];
var webworkerReader = new FileReader();
webworkerReader.onload = function(){
var binaryStr = webworkerReader.result;
var base64Str = btoa(binaryStr);
webworkerReader.readAsBinaryString(fileObj);
};
}
onclick(){
fileSelected(this.inputObj);
}
}
为什么会出现此错误?如何解决?
【问题讨论】:
-
请提供您收到此错误的代码!
标签: angular