image upload in angular

   <input class="display1"

                        type="file"

                        id="fileInput"

                        name="fileInput"

                        accept="image/*" 

                        (change)="selectFiles($event)"

                      />



selectFiles(event: any): void {

    

    this.selectedFileNames = [];

    this.selectedFiles = event.target.files;

    this.previews = [];

    if (this.selectedFiles && this.selectedFiles[0]) {

      const numberOfFiles = this.selectedFiles.length;

      for (let i = 0; i < numberOfFiles; i++) {

        const reader = new FileReader();

        reader.onload = (e: any) => {

          // console.log(e.target.result);

          this.previews.push(e.target.result);

          console.log(this.previews[0],"this.previews");

        };

        reader.readAsDataURL(this.selectedFiles[i]);

        this.selectedFileNames.push(this.selectedFiles[i].name);

      }

    }

    // console.log(this.selectedFiles,"this.selectedFiles");

   


  }

Comments

Popular posts from this blog

How to Add Firebase Analytics to Your NativeScript Mobile App

sidemenu refresh through events

push multiple data in array(select and disselect items in array)