Sujeet Raman

Sujeet Raman

  • 864
  • 927
  • 352.9k

Angular2 Cannot read property 'nativeElement' of undefined

Aug 2 2017 4:06 AM
I am trying to get datas from component in html,one upload image function is there.
but am getting   'nativeElement' of undefined error.what mistake i did?
 
 import { Component, OnInit, ElementRef } from '@angular/core';
 
 
public uploadImage(): void {
alert("file methode strike");
this.elem.nativeElement.querySelector('#spinner').style.visibility = 'visible';
let files = this.elem.nativeElement.querySelector('#selectFile').files;
let formData = new FormData();
let file = files[0];
formData.append('selectFile', file, file.name);
this._StartpageAdminservice.uploadImage(formData).subscribe(
res => this.dataLoaded(res));
console.log(this.dataLoaded);
 
private dataLoaded(data: any): void {
this.elem.nativeElement.querySelector('#spinner').style.visibility = 'hidden';
}
 
 
 
 html(which is inside a
tag)
 
 

Answers (3)