类型“ EventTarget”上不存在属性“结果”

时间:2019-06-27 05:09:57

标签: angular

我在事件类型上遇到以下错误。错误:类型“ EventTarget”上不存在属性“结果”。

我的.ts文件,

select4File(event) {
    if (event.target.files && event.target.files[0]) {
        var reader = new FileReader();

        reader.readAsDataURL(event.target.files[0]); // read file as data url

        reader.onload = (event) => { // called once readAsDataURL is completed
            this.imageurl2 = event.target.result;


        }
        this.selectedfiles = event.target.files;
    }

}
my html,
 <div class="form-inline" Style="color: black">
          <div class="row">
          <div class="col-md-6 offset-md-3">
            <label style ="color: black">Additional ID Back</label>
            <form >
          <div class="form-inline" >
              <img [src]="imageurl2" height="200"> <br/>
            <input type="file"(change)="select4File($event)"  />
          </div>
            </form>
          </div>
          </div>
            &nbsp; &nbsp;
            <button (click)="uploadADIDback()" class="btn btn-primary" style="margin:0 35%;position:relative;left:-35px;background-color: #3560a5;  /* blue */">Upload</button>
          </div>
          </div>

在这里帮助解决此错误。

3 个答案:

答案 0 :(得分:1)

像魅力一样工作

change(event) {
var file = event.target.files[0];
if (!file) return;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (event) => {
  this.url = reader.result;
}}

答案 1 :(得分:0)

您已经从父函数中获得了event变量。重命名onload回调事件变量

 reader.onload = (e) => { // called once readAsDataURL is completed
      this.imageurl2 = e.target.result; 
 }

答案 2 :(得分:0)

尝试一下:

  reader.onload = () => {
    // called once readAsDataURL is completed
    this.imageurl2 = reader.result;
  };