File Upload with Angular Material

后端 未结 12 1052
抹茶落季
抹茶落季 2021-01-30 15:48

I\'m writing an web app with AngularJS and angular-material. The problem is that there\'s no built-in component for file input in angular-material. (I feel that file uploading d

12条回答
  •  清酒与你
    2021-01-30 16:29

    html:
        
    upload image

    app.component.ts

    export class AppComponent {
      options = [{ value: "This is value 1", checked: true }];
      statuses = ["control"];
    
      // name = "Angular";//
      fileToUpload: any;
      imageUrl: any;
      handleFileInput(file: FileList) {
        this.fileToUpload = file.item(0);
    
        //Show image preview
        let reader = new FileReader();
        reader.onload = (event: any) => {
          this.imageUrl = event.target.result;
        };
        reader.readAsDataURL(this.fileToUpload);
      }
    }
    

提交回复
热议问题