Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2-从输入文件读取二进制文件并将其绑定到对象_Angular_Angular2 Forms - Fatal编程技术网

Angular2-从输入文件读取二进制文件并将其绑定到对象

Angular2-从输入文件读取二进制文件并将其绑定到对象,angular,angular2-forms,Angular,Angular2 Forms,我得到了绑定到结构化对象数组的多个文件上传输入的文件二进制内容 情况是这样的: 我有一门课是这样的: export class PriceList { public idPriceList: number; public code: string; public name: string; public binary: any;//this property has to contain the binary content of the selected fil

我得到了绑定到结构化对象数组的多个文件上传输入的文件二进制内容

情况是这样的:

我有一门课是这样的:

export class PriceList {
    public idPriceList: number;
    public code: string;
    public name: string;
    public binary: any;//this property has to contain the binary content of the selected file
}
fileChange($event,t)
然后,我的数组由webapi填充,用于组成表单:

public listFile: PriceList[] = [];
现在,在component中,我实现了一个循环,以便组成一个表单,用户可以在其中为每个PriceList项目选择要上载的文件:

<ng-contrainer *ngFor="let t of listFile">
<tr>
    {{t.code}}<input type="file" id="ImageBinary" (change)="fileChange($event)">
</tr>
</ng-container>
我想将文件的二进制内容绑定到对象的“二进制”属性

我需要将元素传递给fileChange函数,如下所示:

export class PriceList {
    public idPriceList: number;
    public code: string;
    public name: string;
    public binary: any;//this property has to contain the binary content of the selected file
}
fileChange($event,t)
但是如果我扩展这个函数,它就不会被击中

我不知道我该怎么走


感谢支持

将值添加到
文件更改
功能应该很好

我已经包括了一个StackBlitz的链接,显示它正在工作。在这里,is使用FileReader将二进制文件读入ArrayBuffer:


文件更改(事件、项目){
item.binary=事件;
var r=新文件读取器();
r、 onload=函数(e){
item.binary=r.result
}
r、 readAsArrayBuffer(event.target.files[0]);
}