【发布时间】:2016-10-11 14:36:52
【问题描述】:
我有以下组件可以加载文件并将其内容绑定为字符串
export class NgCsvComponent {
@Input() csv: any;
@Output() csvChange: any = new EventEmitter();
public localCsv : any = '';
constructor() { }
changeListener($event): void {
this.readFile($event.target);
}
readFile (inputValue : any) : void {
let reader = new FileReader (),
file : File = inputValue.files[0];
reader.readAsText(file);
reader.onload = this.onLoadCallback;
}
onLoadCallback (event) {
this.csvChange.emit(event.target["result"]);
}
}
问题是this.csvChange 在onLoadCallback 内部未定义,那么我如何将结果传递给组件中的某个变量?
我正在搜索其他类似的question,但从未在 onloadCallback 函数之外得到结果
【问题讨论】:
标签: angular typescript filereader